{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

12.DivideAndConquer_outside

Log is then log is if 2 is then is if 1 log 1 log log

Info iconThis preview shows pages 15–19. Sign up to view the full content.

View Full Document Right Arrow Icon
) 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 1 ) 2 / ( ) ( n T n T Solution: log b a=0, so case 2 says T(n) is O(log n). (binary search)
Background image of page 15

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

View Full Document Right Arrow Icon
© 2004 Goodrich, Tamassia Divide-and-Conquer 16 Master Method, Example 7 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. ) 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 n n T n T log ) 2 / ( 2 ) ( Solution: log b a=1, so case 1 says T(n) is O(n). (heap construction)
Background image of page 16
© 2004 Goodrich, Tamassia Divide-and-Conquer 17 Iterative “Proof” of the Master Theorem Using iterative substitution, let us see if we can find a pattern: We then distinguish the three cases as The first term is dominant Each part of the summation is equally dominant The summation is a geometric series 1 ) (log 0 log 1 ) (log 0 log 2 2 3 3 2 2 2 ) / ( ) 1 ( ) / ( ) 1 ( . . . ) ( ) / ( ) / ( ) / ( ) ( ) / ( ) / ( )) / ( )) / ( ( ) ( ) / ( ) ( n i i i a n i i i n b b b b b n f a T n b n f a T a n f b n af b n f a b n T a n f b n af b n T a bn b n f b n aT a n f b n aT n T
Background image of page 17

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

View Full Document Right Arrow Icon
© 2004 Goodrich, Tamassia Divide-and-Conquer 18 Integer Multiplication Algorithm: Multiply two n-bit integers I and J. Divide step: Split I and J into high-order and low-order bits We can then define I*J by multiplying the parts and adding: So, T(n) = 4T(n/2) + n, which implies T(n) is O(n 2 ). But that is no better than the algorithm we learned in grade school. l n h l n h J J J I I I 2 / 2 / 2 2 l l n h l n l h n h h l n h l n h J I J I J I J I J J I I J I 2 / 2 / 2 / 2 / 2 2 2 ) 2 ( * ) 2 ( *
Background image of page 18
© 2004 Goodrich, Tamassia Divide-and-Conquer 19 An Improved Integer Multiplication Algorithm Algorithm: Multiply two n-bit integers I and J. Divide step: Split I and J into high-order and low-order bits Observe that there is a different way to multiply parts: So, T(n) = 3T(n/2) + n, which implies T(n) is O(n log 2 3 ), by the Master Theorem.
Background image of page 19
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}