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

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/02/2010.

Page1 / 15

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

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online