understanding recursive rules of tower of hanoi

177 views Asked by At

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:

  1. only one disk can be moved among the towers at any given time.
  2. Only the "top" disk can be removed.
  3. No large disk can sit over a small disk.

BUT according to the recursive method:

  1. Move n-1 disks from source to aux.
  2. Move nth disk from source to destination.
  3. 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.

1

There are 1 answers

1
Tyler On BEST ANSWER

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.