12.DivideAndConquer_outside

So thus t(n is o(n log n ibn n t bn n t bn n t bn n t

Info iconThis preview shows pages 5–11. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: So, Thus, T(n) is O(n log n). ibn n T bn n T bn n T bn n T bn n b n T bn n T n T i i ) 2 / ( 2 ... 4 ) 2 / ( 2 3 ) 2 / ( 2 2 ) 2 / ( 2 )) 2 / ( )) 2 / ( 2 ( 2 ) 2 / ( 2 ) ( 4 4 3 3 2 2 2 n bn bn n T log ) ( © 2004 Goodrich, Tamassia Divide-and-Conquer 6 The Recursion Tree Draw the recursion tree for the recurrence relation and look for a pattern: depth T’s size 0 1 n 1 2 n / 2 i 2 i n / 2 i … … … 2 if ) 2 / ( 2 2 if ) ( n bn n T n b n T time bn bn bn … Total time = bn + bn log n (last level plus all previous levels) © 2004 Goodrich, Tamassia Divide-and-Conquer 7 Guess-and-Test Method In the guess-and-test method, we guess a closed form solution and then try to prove it is true by induction: Guess: T(n) < cn log n. Wrong: we cannot make this last line be less than cn log n n bn cn n cn n bn n cn n bn n n c n bn n T n T log log log ) 2 log (log log )) 2 / log( ) 2 / ( ( 2 log ) 2 / ( 2 ) ( 2 if log ) 2 / ( 2 2 if ) ( n n bn n T n b n T © 2004 Goodrich, Tamassia Divide-and-Conquer 8 Guess-and-Test Method, (cont.) Recall the recurrence equation: Guess #2: T(n) < cn log 2 n. if c > b. So, T(n) is O(n log 2 n). In general, to use this method, you need to have a good guess and you need to be good at induction proofs. n cn n bn cn n cn n cn n bn n cn n bn n n c n bn n T n T 2 2 2 2 log log log 2 log log ) 2 log (log log )) 2 / ( log ) 2 / ( ( 2 log ) 2 / ( 2 ) ( 2 if log ) 2 / ( 2 2 if ) ( n n bn n T n b n T © 2004 Goodrich, Tamassia Divide-and-Conquer 9 Master Method (Appendix) Many divide-and-conquer recurrence equations have the form: The Master Theorem: d n n f b n aT d n c n T if ) ( ) / ( if ) ( . 1 some for ) ( ) / ( provided )), ( ( is ) ( then ), ( is ) ( if 3. ) log ( is ) ( then ), log ( is ) ( if 2. ) ( is ) ( then ), ( is ) ( if 1. log 1 log log log log n f b n af n f n T n n f n n n T n n n f n n T n O n f a k a k a a a b b b b b © 2004 Goodrich, Tamassia Divide-and-Conquer 10 Master Method, Example 1 The form: The Master Theorem: Example: d n n f b n aT d n c n T if ) ( ) / ( if ) ( . 1 some for ) ( ) / ( provided )), ( ( is ) ( then ), ( is ) ( if 3.3....
View Full Document

{[ snackBarMessage ]}

Page5 / 19

So Thus T(n is O(n log n ibn n T bn n T bn n T bn n T bn n...

This preview shows document pages 5 - 11. Sign up to view the full document.

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