L11_RecurInduction

L11_RecurInduction - 1-1COMP170Discrete Mathematical...

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

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.2, pp. 143-153Recursion, Recurrences and InductionVersion 2.0: Last updated, May 13, 2007Slidesc2005 by M. J. Golin and G. Trippen2-1Recursion, Recurrences and Induction•Recursion•Recurrences•Iterating a Recurrence•Geometric Series•First-Order Linear Recurrences3-1Recursion3-2Recursion•Recursive computer programs or algorithms often leadto inductive analyses3-3Recursion•Recursive computer programs or algorithms often leadto inductive analyses•A classic example of this is theTowers of Hanoiproblem4-1Towers of Hanoi4-2Towers of Hanoi4-3Towers of Hanoi•3pegs;ndisks of different sizes.•Alegal movetakes a disk from one peg and moves it ontoanother peg so that it is not on top of a smaller disk•Problem: Find a (efficient) way to move all of the disksfrom one peg to another5-1Towers of Hanoi5-2Towers of Hanoilegal move⇒5-3Towers of Hanoilegal movelegal move⇒⇒5-4Towers of Hanoilegal movelegal movenot legal⇒⇒⇒5-5Towers of Hanoilegal movelegal movenot legallegal move⇒⇒⇒⇒6-1Towers of HanoiProblem6-2Towers of HanoiStart withndiskson leftmost pegProblem6-3Towers of HanoiStart withndiskson leftmost pegusingonlylegal moves⇒Problem6-4Towers of HanoiStart withndiskson leftmost pegusingonlylegal moves⇒Problemmove all disks torightmost peg.6-5Towers of HanoiStart withndiskson leftmost pegusingonlylegal movesGiveni, j∈ {1,2,3}let{i, j}={1,2,3} - {i} - {j}⇒Problemmove all disks torightmost peg.i.e.,{1,2}= 3,{1,3}= 2,{2,3}= 1.7-1Towers of HanoiGeneral Solution7-2Towers of HanoiRecursion Base:Ifn= 1moving one disk fromitojis easy.Just move it.General Solution7-3Towers of HanoiRecursion Base:Ifn= 1moving one disk fromitojis easy.Just move it.⇒General Solution8-1Towers of HanoiTo moven >1disksfromitoj8-2Towers of HanoiTo moven >1disksfromitojmove topn-1disksfromito{i, j}1)8-3Towers of HanoiTo moven >1disksfromitojmove topn-1disksfromito{i, j}1)move largest diskfromitoj2)8-4Towers of HanoiTo moven >1disksfromitojmove topn-1disksfromito{i, j}1)move largest diskfromitoj2)move topn-1disksfrom{i, j}toj.3)9-1To movendisks fromitoji) move topn-1disksfromito{i, j}ii) move largest diskfromitojiii) move topn-1disksfrom{i, j}toj.9-2To movendisks fromitoji) move topn-1disksfromito{i, j}ii) move largest diskfromitojiii) move topn-1disksfrom{i, j}toj.•To proveCorrectnessofsolution we are implicitlyusing induction9-3To movendisks fromitoji) move topn-1disksfromito{i, j}ii) move largest diskfromitojiii) move topn-1disksfrom{i, j}toj.•To proveCorrectnessofsolution we are implicitlyusing induction•p(n)is statement thatalgorithm is correct forn9-4To movendisks fromitoji) move topn-1disksfromito{i, j}ii) move largest diskfromitojiii) move topn-1disksfrom{i, j}toj....
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 / 165

L11_RecurInduction - 1-1COMP170Discrete Mathematical...

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

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