The Tower of Hanoi Ben Epstein Special Topics 2003.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Discrete Math Recurrence Relations 1.
Tower of Hanoi Tower of Hanoi is a mathematical puzzle invented by a French Mathematician Edouard Lucas in The game starts by having few discs stacked.
The Towers of Hanoi or Apocalypse When?.
The Tower Of Hanoi Edouard Lucas
Week 6 - Wednesday CS322.
Chapter Recurrence Relations
More Recursion: Permutations and Towers of Hanoi COP 3502.
AE1APS Algorithmic Problem Solving John Drake
Analyzing Algorithms and Problems Prof. Sin-Min Lee Department of Computer Science.
Data Structures and Algorithms
1 On a question of Leiss regarding the Towers of Hanoi problem.
Chapter 10 Recursion. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Explain the underlying concepts of recursion.
Recursion.
Recursion!. Question Stephen King’s books J. R. R. Tolkien’s books Recursion Do they have something in common?
Review of Recursion. Definition: Recursion - The process of a function calling itself.
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
6.Advanced Counting Techniques 1 Copyright M.R.K. Krishna Rao 2003 Ch 6. Recurrence Relations A recurrence relation for the sequence {a n } is an equation.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Introduction to Programming (in C++) Recursion Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
Copyright © Cengage Learning. All rights reserved.
Recursively Defined Sequences Lecture 35 Section 8.1 Wed, Mar 23, 2005.
Advanced Counting Techniques
Sequences defined recursively
Towers of Hanoi. Introduction This problem is discussed in many maths texts, And in computer science an AI as an illustration of recursion and problem.
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
25-2 Recursive Functions Related Chapter: ABC 5.14, 5.15.
RMIT University; Taylor's College1 Lecture 6  To apply the Principle of Mathematical Induction  To solve the Towers of Hanoi puzzle  To define a recurrence.
Kontraktbaseret Programmering 1 Induction and Recursion Jens Bennedsen.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Data Structures: A Pseudocode Approach with C1 Chapter 2 Objectives Upon completion you will be able to: Explain the difference between iteration and recursion.
Recursion Jordi Cortadella Department of Computer Science.
# 1# 1 VBA Recursion What is the “base case”? What is the programming stack? CS 105 Spring 2010.
Chapter 4 Recursion. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Explain the underlying concepts of recursion.
Whiteboardmaths.com © 2004 All rights reserved
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
MATHS FOR GENIUS: TOWER OF HANOI Pedro Luis Fernández Martínez.
Upon completion, the world will end…
Chapter 6.1: Recurrence Relations Discrete Mathematical Structures: Theory and Applications.
 STACK STACK  STACK OPERATIONS STACK OPERATIONS  PUSH ALGORITHM PUSH ALGORITHM  POP ALGORITHM POP ALGORITHM  USES OF STACK USES OF STACK  THE TOWER.
Recursion Colin Capham Recursion – an introduction to the concept.
Pass the Buck Every good programmer is lazy, arrogant, and impatient. In the game “Pass the Buck” you try to do as little work as possible, by making your.
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
UNIT 17 Recursion: Towers of Hanoi.
CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 9: The Tower of Hanoi.
1 In this puzzle, the player begins with n disks of decreasing diameter placed one on top of the other on one of three pegs of the game board. The player.
Tower of Hanoi Tower of Hanoi is a mathematical puzzle invented by a French Mathematician Edouard Lucas in The game starts by having few discs stacked.
Recursively Defined Sequences Lecture 40 Section 8.1 Wed, Apr 11, 2007.
Recursion (Continued)
Tower of Hanoi problem: Move the pile of rings from one peg to another
CSCE 3110 Data Structures & Algorithm Analysis
Recursion.
Pramada Ramachandran, Assistant Professor, Department of Mathematics,
Chapter 4 Stacks
Introduction to Recurrence Relations
CSCE 3110 Data Structures & Algorithm Analysis
School of EECS, Peking University
Whiteboardmaths.com © 2004 All rights reserved
CSCE 3110 Data Structures & Algorithm Analysis
Copyright © Cengage Learning. All rights reserved.
ECE 103 Engineering Programming
When Will The World End “Temple of Brahma” legend from the Indian city of Benares Priests must move 64 gold disks from one end of the temple to the other.
Tower of Hanoi problem: Move the pile of rings from one peg to another
Copyright © Cengage Learning. All rights reserved.
The Hanoi Tower Problem
1A Recursively Defined Functions
Problem Solving WEEK 3.
Tower of Hanoi problem: Move the pile of rings from one peg to another
Recursively Defined Sequences
Presentation transcript:

The Tower of Hanoi Ben Epstein Special Topics 2003

Lucas and The Tower of Brahma Origins of The Tower of Hanoi The Tower of Hanoi puzzle was invented in 1883 by the French mathematician Edouard Lucas. A year later another French mathematician, De Parville, composed the following tale commonly associated with The Tower of Hanoi. "In the great temple at Benares, says he, beneath the dome which marks the centre of the world, rests a brass plate in which are fixed three diamond needles, each a cubit high and as thick as the body of a bee. On one of these needles, at the creation, God placed sixty-four discs of pure gold, the largest disc resting on the brass plate, and the others getting smaller and smaller up to the top one. This is the Tower of Bramah. Day and night unceasingly the priests transfer the discs from one diamond needle to another according to the fixed and immutable laws of Bramah, which require that the priest on duty must not move more than one disc at a time and that he must place this disc on a needle so that there is no smaller disc below it. When the sixty-four discs shall have been thus transferred from the needle on which at the creation God placed them to one of the other needles, tower, temple, and Bramahns alike will crumble into dust, and with a thunderclap the world will vanish."

How To Play The puzzle consists of p pegs and d disks, with each disk being a different size. The object is to relocate the entire tower to a different peg. The stipulations are that only one disk can be moved at a time and no disk can be placed atop a smaller disk. We will examine the puzzle when and.

Peg Labeling In order to explain the solutions we must distinguish between the pegs. So let the peg on which the tower sits be the source peg. Call the peg you wish to move to the destination peg. Call the peg necessary for auxiliary moves the auxiliary peg. NOTE: A new tower will be created with every move. Consequently, the pegs which we initially called the source, auxiliary and destination pegs will constantly change. Source PegAuxiliary PegDestination Peg

Preliminary Observations Let q equal to the minimum number of moves necessary to complete the relocation. Examining the case when d = 3 we find q = 7. d = 7 d = 6 d = 8 q = 63 q = 127 q = 255 d = 5 d = 4q = 15 q = 31 Can you see the pattern?

The following equation gives q for any d: This will be true for all d provided that p = 3. In the case of De Parville’s story the priests had to relocate a tower of 64 disks. Therefore: Supposing that the priests were proficient enough to make a move a second, the world would end in 584,942,417,355.1 years. Observations Continued

Move Sequence for d = 3

More Observations When looking at the case of d = 3 the first move must be made to the destination peg to ensure a solution with minimal q. Similarly, for d = 4 the first move must be made to the auxiliary peg. It will be the case that for odd d the first move must always be made to the destination peg. For even d the first move must always be made to the auxiliary peg.

Recurrence Relations Another way of approaching this problem is to look at the first d – 1 disks. The goal would then be to first relocate those disks to the auxiliary peg. Next one would simply move the last disk to the destination peg. Finally, the solution would be achieved by relocating the d – 1 disk tower to the destination peg. This method gives rise to the notion of recurrence.

Move Sequence for d = 3

Recurrence Relations Continued Consider T(d), where T(d) = q and d = 3 and q = 7. We know T(3) = 7. Using the recurrence relation we can see that In this example T(3-1) is the number of moves to relocate the top two disks. Clearly this must be done twice: once to uncover the largest disk and again to re-cover it, therefore it is multiplied by two. The “+1” comes from the single move of the largest disk from the source to destination peg. Likewise, for all d except d = 0 the following holds: NOTE: T(0) = 0

Sierpinski’s Gasket

Sierpinski’s Gasket d1d1d2d2d3 311 Peg #

Class Exercises What is T(15)? Draw the move sequence for d = 4.