(2116 Views)

Tower of Hanoi, is a mathematical puzzle which consists of three towers.These rings are of varying sizes sizes and stacked upon each other in ascending order. There are other variations of the puzzle where the number of disks increase, but the tower count remains the same.

Source: Wikipedia

A few rules that need to be followed for Tower of Hanoi are -

1.The top disk can be moved only. 2.Only one disk can be moved at a time. 3.No large disk sits above a small disk.

With 3 disks, the puzzle can be solved in 7 moves. The minimal number of moves required to solve a Tower of Hanoi puzzle is 2^{n} ? 1, where n is the number of disks.

In the above algorithm,

- Consider three towers source, dest, aux and take value of disks from the user.
- Now we move all the above n-1 disks one by one from source to aux.
- The largest disk is left at the source, which is then moved to the dest tower.
- Then again the rest of the disks are moved back from aux to source.
- Again the same steps are repeated so that all the disks are moved to the dest tower.

13 UpvotesUpvote |
4 DownvotesDownvote |

- Prime Number program in Python [893 Views]
- Difference between #define and const in C [1534 Views]
- 10 useful python tips and tricks for programmers [274 Views]
- Writable Streams in Javascript [990 Views]
- Pseudocode and Algorithm to find Largest of 2 numbers [1655 Views]

- Algorithm to find whether number is Armstrong Number or Not [40208 Views]
- How To Win Ludo King Game Every Time [39340 Views]
- Jio Phone hang on LOGO problem Solution - Hard Reset Jio Phone [27644 Views]
- Knuth-Morris-Pratt (KMP) Substring Search Algorithm with Java Example [27544 Views]
- FlowChart and Algorithm to find Whether a Number is Even or Odd [20020 Views]