Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

3,964 views

Published on

Tower of Hanoi

No Downloads

Total views

3,964

On SlideShare

0

From Embeds

0

Number of Embeds

4

Shares

0

Downloads

223

Comments

0

Likes

8

No embeds

No notes for slide

- 1. Created By ANKIT S. CHITNAVIS
- 2. Tower of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following rules: 1.Only one disk must be moved at a time. 2.Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod. 3.No disk may be placed on top of a smaller disk.
- 3. The puzzle can be played with any number of disks. The minimum number of moves required to solve a Tower of Hanoi puzzle is 2n - 1 where n is the number of disks. Solution for Tower of Hanoi :For an even number of disks: make the legal move between pegs A and B make the legal move between pegs A and C make the legal move between pegs B and C repeat until complete For an odd number of disks: make the legal move between pegs A and C make the legal move between pegs A and B make the legal move between pegs C and B repeat until complete. In each case, a total of 2ⁿ-1 moves are made.
- 4. Algorithm Input :- Input of discs in Tower of Hanoi , specification of ORG as from the piller and DES as to piller,INT as the intemediate piller. Output :- Steps of moves of N discs from piller ORG to DCS piller. Steps 1. if N>0 then 2. move(N-1 ,ORG ,DES ,INT) 3. ORG DES (move from ORG to DES) 4. move(N-1 ,INT ,ORG ,DES) 5. end if 6. stop
- 5. For N=3 , how will this recursion solve the problem as shown Move(2,A,C,B) A B Move(1,C,A,B) Move(3,A,B,C) A C Move(1,B,C,A) Move(2,B,A,C) B C MoveE(1,A,B,C) C ( 1) A B (2) C B (3) A Move(1,A,B,C) A C (4) B A (5) B C (6) A C (7)
- 6. Example :- For 3 disk Move= - 1= 7
- 7. Thank You

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment