L12_SolutionsRecurrences_b

L12_SolutionsRecurrences_b - 1-1COMP170Discrete...

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

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

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

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-1COMP170Discrete Mathematical Toolsfor Computer ScienceDiscrete Math for Computer ScienceK. Bogart, C. Stein and R.L. DrysdaleSection 4.3, pp. 157-167Solutions to RecurrencesVersion 2b.2: Last updated, November 1, 2007Slidesc2005 by M. J. Golin and G. TrippenVersion without recursion trees2-1Growth Rates of Solutions to Recurrences•Divide and Conquer Algorithms•Three Different Behaviors•Iterating Recurrences3-1Divide and Conquer Algorithms3-2Divide and Conquer AlgorithmsIn the previous section we analyzed recurrences of the formT(n) =aifn=bc·T(n-1) +difn > b3-3Divide and Conquer AlgorithmsIn the previous section we analyzed recurrences of the formT(n) =aifn=bc·T(n-1) +difn > bThese corresponded to the analyses of recursive algorithms in whicha problem of sizenis solved by recursively solving a problem(s) ofsizen-1.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 form3-4Divide and Conquer AlgorithmsIn the previous section we analyzed recurrences of the formT(n) =aifn=bc·T(n-1) +difn > bThese corresponded to the analyses of recursive algorithms in whicha problem of sizenis solved by recursively solving a problem(s) ofsizen-1.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 > b4-1Divide 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:4-2Divide 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?4-3Divide 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 toquestion5-1Binary Search Example5-23248164Binary Search Example5-33248164Binary Search ExampleIsx >32?5-43248164Binary Search ExampleIsx >32?Answer: Yes5-53248164Binary Search ExampleIsx >32?Answer: YesIsx >48?5-63248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: No5-73248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?5-83248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?Answer: No5-93248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?Answer: NoIsx >36?5-103248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?Answer: NoIsx >36?Answer: No5-113248164Binary Search ExampleIsx >32?Answer: YesIsx >48?Answer: NoIsx >40?Answer: NoIsx >36?Answer: NoIsx >34?5-12...
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 / 142

L12_SolutionsRecurrences_b - 1-1COMP170Discrete...

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

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