L12_SolutionsRecurrences_b_print

L12_SolutionsRecurrences_b_print - 1 COMP170 Discrete...

Info iconThis preview shows pages 1–7. 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 DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 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 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 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! 6 T ( n ) = T ( n/ 2) + 1 if n ≥ 2 , 1 if n = 1 ....
View Full Document

This note was uploaded on 08/25/2010 for the course COMP COMP170 taught by Professor M.j.golin during the Spring '10 term at HKUST.

Page1 / 27

L12_SolutionsRecurrences_b_print - 1 COMP170 Discrete...

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

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