(2120 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 |

- How to convert the number into Characters in a sentence using C++ [186 Views]
- Huffman's Coding Greedy Algorithm [389 Views]
- Python Slice Notation [223 Views]
- Inbuilt data structure in Python [121 Views]
- Setting Up Unity for Installing Application on Android Device [2486 Views]

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