{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

note02-1x2

# note02-1x2 - Compare the growth rate of functions We have...

This preview shows pages 1–5. Sign up to view the full content.

Compare the growth rate of functions We have two algorithms A 1 and A 2 for solving the same problem, with runtime functions T 1 ( n ) and T 2 ( n ) , respectively. Which algorithm is more efficient? We compare the growth rate of T 1 ( n ) and T 2 ( n ) . If T 1 ( n ) = Θ( T 2 ( n )) , then the efficiency of the two algorithms are about the same ( when n is large ). If T 1 ( n ) = o ( T 2 ( n )) , then the efficiency of the algorithm A 1 will be better than that of algorithm A 2 ( when n is large ). By using the definitions, we can directly show whether T 1 ( n ) = O ( T 2 ( n )) , or T 1 ( n ) = Ω( T 2 ( n )) . However, it is not easy to prove the relationship of two functions in this way. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 2 / 36 Limit Test Limit Test is a powerful method for comparing functions. Limit Test Let T 1 ( n ) and T 2 ( n ) be two functions. Let c = lim n →∞ T 1 ( n ) T 2 ( n ) . 1 If c is a constant > 0 , then T 1 ( n ) = Θ( T 2 ( n )) . 2 If c = 0 , then T 1 ( n ) = o ( T 2 ( n )) . 3 If c = , then T 1 ( n ) = ω ( T 2 ( n )) . 4 If c does not exists (or if we do not know how to compute c ), the limit test fails. Proof of (1): c = lim n →∞ T 1 ( n ) T 2 ( n ) means: > 0 , there exists n 0 0 such that for any n n 0 : T 1 ( n ) T 2 ( n ) - c ; or equivalently: c - T 1 ( n ) T 2 ( n ) c + . Let = c / 2 and let c 1 = c - = c / 2 and c 2 = c + = 3 c / 2 , we have c 1 T 2 ( n ) T 1 ( n ) c 2 T 2 ( n ) for all n n 0 . Thus T 1 ( n ) = Θ( T 2 ( n )) by definition. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 4 / 36

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example Example 1 T 1 ( n ) = 10 n 2 + 15 n - 60 , T 2 ( n ) = n 2 lim n →∞ T 1 ( n ) T 2 ( n ) = lim n →∞ 10 n 2 + 15 n - 60 n 2 = lim n →∞ ( 10 + 15 n - 60 n 2 ) = 10 + 0 - 0 = 10 Since 10 is a constant > 0 , we have T 1 ( n ) = Θ( T 2 ( n )) = Θ( n 2 ) by the statement 1 of Limit Test (as expected). c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 5 / 36 Log function The log functions are very useful in algorithm analysis. lg = log 2 n log n = log 10 n ln n = log e n ( ln n is the log function with the natural base e = 2 . 71828 . . . ). c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 6 / 36
Log base change formula Log base change formula For any 1 < a , b , log b n = log a n log a b = log b a · log a n . Proof: Let k = log b n . By definition: n = b k . Take log a on both sides: log a n = log a ( b k ) = k · log a b This implies: log b n = k = log a n log a b . Let n = a in this formula and note 1 = log a a : log b a = log a a log a b = 1 log a b This proves the second part of the formula. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 7 / 36 L’Hospital Rule L’Hospital Rule If lim n →∞ f ( n ) = 0 and lim n →∞ g ( n ) = 0 , then lim n →∞ f ( n ) g ( n ) = lim n →∞ f ( n ) g ( n ) If lim n →∞ f ( n ) = and lim n →∞ g ( n ) = , then lim n →∞ f ( n ) g ( n ) = lim n →∞ f ( n ) g ( n ) c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 9 / 36

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example Example 2 T 1 ( n ) = n 2 + 6 , T 2 ( n ) = n lg n . (Recall: lg n = log 2 n .) lim n →∞ T 1 ( n ) T 2 ( n ) = lim n →∞ n 2 + 6 n lg n = lim n →∞ n + 6 n lg n = lim n →∞ 1 - 6 n 2 1 ln 2 · n (by L’Hospital Rule) = ln 2 lim n →∞ ( n - 6 n ) = ln 2 ( ∞ - 0 ) = By limit Test, we have n 2 + 6 = ω ( n lg n ) .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}