This preview shows pages 1–21. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 11COMP170Discrete Mathematical Toolsfor Computer ScienceDiscrete Math for Computer ScienceK. Bogart, C. Stein and R.L. DrysdaleSection 4.3, pp. 157167Solutions to RecurrencesVersion 2b.2: Last updated, November 1, 2007Slidesc2005 by M. J. Golin and G. TrippenVersion without recursion trees21Growth Rates of Solutions to Recurrences•Divide and Conquer Algorithms•Three Different Behaviors•Iterating Recurrences31Divide and Conquer Algorithms32Divide and Conquer AlgorithmsIn the previous section we analyzed recurrences of the formT(n) =aifn=bc·T(n1) +difn > b33Divide and Conquer AlgorithmsIn the previous section we analyzed recurrences of the formT(n) =aifn=bc·T(n1) +difn > bThese corresponded to the analyses of recursive algorithms in whicha problem of sizenis solved by recursively solving a problem(s) ofsizen1.We will now look at recurrences that arise from recursive algorithmsin which problems of sizenare solved by recursively solving problemsof sizen/m, for some fixedm. These recurrences will be in the form34Divide and Conquer AlgorithmsIn the previous section we analyzed recurrences of the formT(n) =aifn=bc·T(n1) +difn > bThese corresponded to the analyses of recursive algorithms in whicha problem of sizenis solved by recursively solving a problem(s) ofsizen1.We will now look at recurrences that arise from recursive algorithmsin which problems of sizenare solved by recursively solving problemsof sizen/m, for some fixedm. These recurrences will be in the formT(n) =something givenifn≤bc·T(n/m) +difn > b41Divide and Conquer AlgorithmsOur first example will bebinary search.Someone has chosen a numberxbetween1andn.We need to discoverx.We are only allowed to ask two types of questions:42Divide and Conquer AlgorithmsOur first example will bebinary search.Someone has chosen a numberxbetween1andn.We need to discoverx.We are only allowed to ask two types of questions:•Isxgreater thank?•Isxequal tok?43Divide and Conquer AlgorithmsOur first example will bebinary search.Someone has chosen a numberxbetween1andn.We need to discoverx.We are only allowed to ask two types of questions:•Isxgreater thank?•Isxequal tok?Our strategy will be to always askgreater thanquestions,at each step halving our search range,until the range only contains one number,when we ask a finalequal toquestion51Binary Search Example523248164Binary Search Example533248164Binary Search ExampleIsx >32?543248164Binary Search ExampleIsx >32?Answer: Yes553248164Binary Search ExampleIsx >32?Answer: YesIsx >48?563248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: No573248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?583248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?Answer: No593248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?Answer: NoIsx >36?5103248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?Answer: NoIsx >36?Answer: No5113248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?Answer: NoIsx >36?Answer: NoIsx >34?512...
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.
 Spring '10
 M.J.Golin
 Computer Science, Recursion

Click to edit the document details