Your SlideShare is downloading. ×
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Tower of Hanoi

516

Published on

Tower of Hanoi

Tower of Hanoi

Published in: Education, Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
516
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
23
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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

×