I am a beginner in data structures and algorithms and recently came across the tower of hanoi algorithm. I see a clash that i can't figure out between the rules of tower of hanoi (recursion method) and the standard way the clash is:
According to the standard rules:
- only one disk can be moved among the towers at any given time.
- Only the "top" disk can be removed.
- No large disk can sit over a small disk.
BUT according to the recursive method:
- Move n-1 disks from source to aux.
- Move nth disk from source to destination.
- Move n-1 disks from aux to destination.
as you can see, there's a difference between the 1st and 2nd rules of both the methods.
To help you understand what the second method means, when it says move n-1 disks from source to aux, this means take from the top of source n-1 times, and move the top disk to aux. So one disk is moved at a time still, and the top disk is removed each time. Then the nth disk is now the top, so it can be moved to destination. Now you can repeat for step 3.