1 / 17

Lecture 6

Lecture 6. To apply the Principle of Mathematical Induction To solve the Towers of Hanoi puzzle To define a recurrence relation. Mathematical Induction. Suppose we have a mathematical proposition, P ( n ), about some integers n .

hewitt
Télécharger la présentation

Lecture 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 6 To apply the Principle of Mathematical Induction To solve the Towers of Hanoi puzzle To define a recurrence relation RMIT University; Taylor's College

  2. Mathematical Induction • Suppose we have a mathematical proposition, P(n), about some integers n. • We want to know if P(n) is true for every integer n, from astarting point onwards. RMIT University; Taylor's College

  3. Mathematical Induction Example: Prove that n! > 2n is true for all in positive integer n Is this sometimes true, never true, always true after a certain point, or what? How could we prove n! > 2n? The idea is to use Proof by Induction. At this stage, n! seems to be streaking ahead of 2n at a great rate. RMIT University; Taylor's College

  4. Proof by Induction: 3 Steps • Base step: With a starting point n0, Verify that P(n0) is true. • Inductive step: Assume that P(k) is true, prove that P(k+ 1) is also true. • Conclusion: Declare that P(n) is true for every integer n ≥ n0 RMIT University; Taylor's College

  5. Example:Prove by induction that n! > 2n for all n ≥ 4. Base Step: Verify that P(4) is true. LHS = 4! = 24 RHS = 24 = 16 Since 24 > 16, n! > 2nis true when . RMIT University; Taylor's College

  6. Example:Prove by induction that n! > 2n for all n ≥ 4. • Inductive Step: • AssumeP(k) : k! > 2k is true. • Prove that P(k + 1): (k + 1)! > 2k+1 is true. • LHS • RHS • Note that so then .P(k + 1): (k + 1)! > 2k+1 is true Conclusion:n! > 2n for all n ≥ 4.

  7. Example:Prove that for every positive integer n. Base step: Verifying P(1),

  8. Example:Prove that for every positive integer n. Inductive step: AssumeP(k): is true. Prove that P(k + 1) is also true. LHS RHS

  9. Example:Prove that for every positive integer n. Conclusion: The statement is true for every positive integer n. RMIT University; Taylor's College

  10. The Towers of Hanoi • We need to move all n discs to Pole 3. But we can only move 1 disc at a time, and a disc must never be placed on a smaller disc. • Theorem: This can be solved for all n ≥ 1 • Proof: We can use proof by induction RMIT University; Taylor's College

  11. The Towers of Hanoi: Proof • Base step • Suppose we have 1 disc. Pick it up and put it on Pole 3 • Inductive step • Suppose we can move (k – 1) discs. ----- (*) • We want to show we can move k discs. • Given k discs, leave the big one at the bottom. Move the other (k – 1) to Pole 2 instead of Pole 3. (We know this can be done, by the inductive hypothesis (*)) • Move the big disc to Pole 3. • Move the other stack from Pole 2 to Pole 3 (Again, we know this can be done, by (*).) • We’ve moved the stack of k discs! • Conclusion • For all n, the problem can be solved. RMIT University; Taylor's College

  12. The Towers of Hanoi • How many moves (1 disc at a time) are needed to get the stack of n discs from Pole 1 to Pole 3? Let this number be fn. • So f1 = 1. (That is, if we only have 1 disc then a single move takes it to Pole 3.) • Let’s look at the inductive proof that the puzzle can always be solved. When n = k, fk moves are needed. • So what happens when n = k + 1? The number of moves needed is fk+1, but this can be expressed in terms of fk. • It takes fk moves to get the top k discs to Pole 2, then 1 move to get the bottom disc to Pole 3, and then fk moves to get the stack of k discs from Pole 2 and put it on top of the biggest disc which is now on Pole 3. RMIT University; Taylor's College

  13. The Towers of Hanoi • So fk+1 = fk + 1 + fk, i.e. fk + 1 = 2fk + 1 • This equation is an example of a recurrence relation, where each value of a function can be determined from previous values (assuming that we know some initial values). • Using n instead of k, we have fn+1 = 2fn + 1 with initial conditionf1 = 1. RMIT University; Taylor's College

  14. The Towers of Hanoi We can then construct the following partial table. f2 = 2f1 + 1 = 2 + 1 =3 f3 = 2f2 + 1 = 6 + 1 = 7 RMIT University; Taylor's College

  15. The Towers of Hanoi • But suppose we want to know how many moves are needed to shift 100 discs. We would need to compute all the values from f7 up to f99, and then use f100 = 2f99 + 1 to get the value of f100. • Clearly it would be better if we had a formula for fn which only depended on n, rather than on earlier values of the function. • Such a formula is called a solution to the recurrence relation. • We won’t give a general method for solving recurrence relations, but rather we’ll look at how to obtain a solution for this particular example. RMIT University; Taylor's College

  16. The Towers of Hanoi • Do the values in the second column of the table look familiar? • If not, let’s add 1 to every value and also put in some more rows. n fn fn + 1 Now it should be clear that the new last column consists of all the powers of 2 with positive exponent. 1 1 2 2 3 4 3 7 8 4 15 16 Specifically, fn + 1 = 2n. 5 31 32 Subtracting 1 from both sides gives fn = 2n – 1. 6 63 64 7 127 128 8 255 256 It can be formally proved that this formula gives the correct answer. (We omit the details.) 9 511 512 19 1023 1024 RMIT University; Taylor's College

  17. The Towers of Hanoi • Our reasoning here is an example of inductive reasoning, where we study enough examples to be able to hypothesize a general result. • Note that f100 = 2100 – 1, which is a rather big number! • 264 – 1 = 18, 446, 744, 073, 709, 551, 615 moves! RMIT University; Taylor's College

More Related