{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L12_SolutionsRecurrences_b_print

# L12_SolutionsRecurrences_b_print - COMP170 Discrete...

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

1 COMP170 Discrete Mathematical Tools for Computer Science Discrete Math for Computer Science K. Bogart, C. Stein and R.L. Drysdale Section 4.3, pp. 157-167 Solutions to Recurrences Version 2b.1: Last updated, October 16, 2007 Slides c 2005 by M. J. Golin and G. Trippen Version without recursion trees

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

View Full Document
2 Growth Rates of Solutions to Recurrences Divide and Conquer Algorithms Three Different Behaviors Iterating Recurrences
3 Divide and Conquer Algorithms In the previous section we analyzed recurrences of the form T ( n ) = a if n = b c · T ( n - 1) + d if n > b These corresponded to the analyses of recursive algorithms in which a problem of size n is solved by recursively solving a problem(s) of size n - 1 . We will now look at recurrences that arise from recursive algorithms in which problems of size n are solved by recursively solving problems of size n/m , for some fixed m . These recurrences will be in the form T ( n ) = something given if n b c · T ( n/m ) + d if n > b

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

View Full Document
4 Divide and Conquer Algorithms Our first example will be binary search . Someone has chosen a number x between 1 and n . We need to discover x . We are only allowed to ask two types of questions: Is x greater than k ? Is x equal to k ? Our strategy will be to always ask greater than questions, at each step halving our search range, until the range only contains one number, when we ask a final equal to question
5 32 48 1 64 Binary Search Example Is x > 32 ? Answer: Yes Is x > 48 ? Answer: No Is x > 40 ? Answer: No Is x > 36 ? Answer: No Is x > 34 ? Answer: Yes Is x > 35 ? Answer: No Method: Each guess reduces the problem to one in which the range is only half as big. This divides the original problem into one that is only half as big; we can now (recursively) conquer this smaller problem. Is x = 35 ? Answer: BINGO!

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

View Full Document
6 T ( n ) = T ( n/ 2) + 1 if n 2 , 1 if n = 1 . Note: Our derivation that, when n is a power of 2 , T ( n ) , the number of questions in a binary search on [1 , n ] , satisfies was actually, implicitly, an inductive proof. This is similar to what we saw with the tower of Hanoi recurrence. We did not write out all the formal steps of the inductive proof, though.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 27

L12_SolutionsRecurrences_b_print - COMP170 Discrete...

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

View Full Document
Ask a homework question - tutors are online