380 likes | 425 Views
Kompleksitas Waktu Asimptotik. CSG3F3 Lecture 5. Intro to asymptotic. f(n)=an 2 + bn + c. Fitting curves to the data. f 1 (n)=0.0007772 n 2 + 0.00305n + 0.001 home computer data f 2 (n)=0.0001724 n 2 + 0.00040n + 0.100 desktop computer data.
E N D
Kompleksitas Waktu Asimptotik CSG3F3 Lecture 5
Intro to asymptotic f(n)=an2 + bn + c RMB/CSG3F3
Fitting curves to the data RMB/CSG3F3
f1(n)=0.0007772 n2 + 0.00305n + 0.001 home computer data f2(n)=0.0001724 n2 + 0.00040n + 0.100 desktop computer data RMB/CSG3F3
Coefficients (a,b,c) associated with particular • computers, • languages, and • compilers RMB/CSG3F3
Introducing the language of O- notation • Dominant terms • Ignoring the constant of proportionality RMB/CSG3F3
O(n2) RMB/CSG3F3
Formal definition RMB/CSG3F3
Asymptotic Notations • Big-oh () • Big-omega () • Big-theta () • Little-oh () • Little-omega () RMB/CSG3F3
-notation • (g(n))={f(n): there exist positive constants c and nonnegative integer nosuch that 0≤f(n) ≤cg(n) for all n ≥ no} • f(n) = O(g(n)) indicates thatf(n) is a member of the set O(g(n)) RMB/CSG3F3
Proof • 100n+5 = O(n2) • 100n+n = 101n, 101n ≤ 101n2, for all n≥5 c=101, no=5 • 100n+5n= 105n, 105n ≤ 105n2, for all n≥1, c=105, no=1 RMB/CSG3F3
T(n)=n+1024=O(n) • T(n)=1+2+…+n=O(n2) • T(n)=10n2+4n+2=O(n2) • T(n)=n2/10+2n=O(2n) • T(n)=6*2n+n2=O(2n) • T(n)=1k+ 2k+…+nk=O(nk+1) • T(n)=log n3= O(log n) RMB/CSG3F3
T(n)=10 log 3n=O(n) • T(n)=2n + 3 2log n=O(n) • T(n)=n!=O(nn) RMB/CSG3F3
-notation • (g(n))={f(n): there exist positive constants c and nonnegative integer nosuch that f(n) ≥cg(n) ≥0 for all n ≥ no} • f(n) = (g(n)) indicates thatf(n) is a member of the set (g(n)) RMB/CSG3F3
Proof • n3 = (n2): n3 ≥ cn2 for all n ≥ 0, We can select c=1 and n0=0 • 3n +2 = Ω(n) : 3n + 2 ≥ 3n for n ≥ 1 • 10n2 + 4n + 2 = Ω (n2 ) : 10n2 + 4n + 2 ≥ n2 RMB/CSG3F3
-notation • (g(n)) ={f(n) : there exist positive constants c1, c2, and nonnegative integer nosuch that c2g(n)≥f(n) ≥c1g(n)≥0 for all n ≥ no} • f(n) = (g(n)) indicates thatf(n) is a member of the set (g(n)) RMB/CSG3F3
Proof • ½n(n-1)= (n2) • Prove the right inequality (upper bound) ½n(n-1)=½n2-½n ≤ ½n2, for all n ≥ 0 • Prove the left inequality (lower bound) ½n(n-1)=½n2-½n ≥ ½n2-½n ½n, for all n ≥ 2 = ¼n2 c1 = ½, c2 = ¼, n0 =2 RMB/CSG3F3
3n + 2 = Θ(n) as 3n + 2 ≥ 3n for all n ≥2, and 3n + 2 ≤ 4n for all n ≥2 , so c1 =3, c2 =4 n0 =2. RMB/CSG3F3
o-notation • o(g(n))={f(n) : for any positive constants c >0, there exist a constant no > 0 such that 0≤f(n) <cg(n) for all n ≥ no} • Example: 2n=o(n2), but 2n2≠o(n2) RMB/CSG3F3
-notation • (g(n))={f(n): for any positive constants c>0, there exist a constant no>0 such that f(n) >cg(n) ≥0 for all n ≥ no} • Example: n2/2= (n), but n2/2≠ (n2) RMB/CSG3F3
Property of asymptotic • If f1(n)єO(g1(n)) and f2(n)єO(g2(n)), then f1(n) + f2(n) є O(max(g1(n),g2(n))) • If f1(n)єO(g1(n)) and f2(n)єO(g2(n)), then f1(n)*f2(n) є O(g1(n)*g2(n)) (also work for and ) RMB/CSG3F3
Asymptotic Analogy RMB/CSG3F3
Complexity Classes RMB/CSG3F3
The Seven Most Important Functions 1.The Constant Function f(n) = c , for some fixed constant c. 2. The Linear Function f(n) = n . 3. The Quadratic Function f(n) = n2 . RMB/CSG3F3
The Seven Most Important Functions 4. Cubic function f(n) = n3 . Polynomials f(n) = a0 + a1 n + a2 n2 + …..+ ad nd integer d is called the degree of the polynomial. 5. Exponential Function f( n) = bn, where b is a positive constant, called the base and the argument n is the exponent. RMB/CSG3F3
The Seven Most Important Functions 6. Logarithm Function f(n) = logb n. 7. N-log-N Function f(n) = n log n. RMB/CSG3F3
Comparing Growth Rates RMB/CSG3F3
Growth of Function Values RMB/CSG3F3
Basic Efficiency Class polynomial exponential RMB/CSG3F3
Exercises • Determine whether the following assertions are true or false • n(n+1)/2 є O(n3) • n(n+1)/2 є O(n2) • n(n+1)/2 є(n3) • n(n+1)/2 є(n) RMB/CSG3F3
References • Levitin, Anany. The design and analysis of algorithms. Pearson Education. 2003. • Cormen., Leiserson., Rivest. Introduction to algorithms. RMB/CSG3F3
Next.. Mathematical analysis of nonrecursive algorithm RMB/CSG3F3