Tower of Hanoi
Solve an interesting problem of recursion named Tower of Hanoi.
We'll cover the following
Problem statement
Tower of Hanoi is a mathematical puzzle where we have three rods and n
disks. The objective of the puzzle is to move the entire stack of disks to another rod, obeying the following simple rules:
- Only one disk can be moved at a time.
- Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
- No disk may be placed on top of a smaller disk.
Implementation
Look at the visualization below to get an understanding of how you can solve this problem for n = 3
disks.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.