---------------------------- 3 ---------------------------- Growth of Functions 3-1a ‘’ 漸近的 3.1 Asymptotic notation “” -notation: f(n) = (g(n)) 3-2 f(n) = (g(n)) iff g(n)=(f(n)), Ex. n2=(3n2-6n) O-notation: f(n) = O(g(n)) g(n) is an asymptotically upper bound for f(n). a set O(g(n))= {f(n)| there exist positive constants c and n0 such that 0 f(n)cg(n) for all n n0} 調大 g(n) is an asymptotically tight bound for f(n). (g(n)) = {f(n)| there exist positive constants c1, c2, and n0 such that 0 c1 g(n)f(n)c2 g(n) for all n n0} 調小 調大 when n is sufficiently large f g g g Example: Prove that 3n2 - 6n = (n2). Proof: To do so, we have to determine c1, c2, and n0 such that f c1n2 3n2 - 6n c2n2, (g(n)) O(g(n)) f(n) = (g(n)) implies f(n) = O(g(n)) 6n = O(n), 6n = O(n2) "The running time is O(n2)" means "the worstcase running time is O(n2)." ‘’ (for all nn0) -notation: f(n) = (g(n)) g(n) is an asymptotically lower bound for f(n). dividing which by n2 yields c1 3 - 6/n c2. 3-1y Clearly, by choosing c1=2, c2=3 and n0=6 we can Q.E.D verify that 3n2 - 6n = (n2). There are many choices! (g(n))= {f(n)| there exists positive constants c and n0 such that 調小 0 cg(n) f(n) for all n n0} 3-3 f(n) = (g(n)) iff (f(n)=O(g(n))) & (f(n)=(g(n))) 3-4 -notation: f(n) = (g(n)) (little-omega of g of n) ‘’ 3-3x (g(n)) = {f(n)| for(any) positive constant c, there exists a constant n0 > 0 such that 0 cg(n) < f(n) for all n n0} tight bound upper bound o(g(n)) = Ο(g(n)) \ Θ(g(n)) ??? o-notation: f(n) = o(g(n)) (little-oh of g of n) o(g(n))= f(n) = (g(n)) iff lim f (n ) = ∞. g ( n ) n →∞ lower bound 3-3y ‘’ 任意大 2n2 = (n), but 2n2 (n2). {f(n)| for (any) positive constant c, there exists a constant n0 > 0 such that 0 f(n) < cg(n) for all n n0} 任意小 2n = o(n2), but 2n2 o(n2). f(n) = o(g(n)) can also be defined as f (n ) lim = 0. n → ∞g ( n ) Comparison of functions functions: O real numbers: Transitivity, Reflexivity, Symmetry, Transpose 3-4x Symmetry Any two real numbers can be compared. (trichotomy) But, not any two functions can be compared. Example: f(n)=n and g(n)=n1+sin n (e)~(h) Homework: Problems 3-2, 3-3, 3-4. lg* n = k 3-4y 3-5 k lglg...lg n 1 3-6 Appendix A: Summation formulas n n n k 1 k 1 k 1 (cak bk ) c ak bk 1 + 2 + ... + n n n 1 k 2 n(n 1) (n 2 ) k 1 x0 + x1+ x2 + ... + xn x k ( x n 1 1) /( x 1) k 0 1 log e n O(1) k k 1 Hn xk k 0 n 1 loge n = 1 x dx n (Harmonic series) = O(lg n) 1 ( x 1) 1 x 3-5x n 1 kx k k 0 x (1 x )2 ( x 1) (differentiating and then multiplying by x) n 1 1 1 1 1 ( ) 1 n k 1 k ( k 1) k 1 k k 1 n n k 1 k 1 lg ak lg ak * n/a /b = n/ab * n/a /b = n/ab * lga b = (lgc b)/(lg c a) * algc b = blgc a