[Math] Variation of Tower of Hanoi

discrete mathematicsrecurrence-relations

I have been reviewing the solution of the following problem for which I have to find a recurrence relation for the number of moves:

"In the Tower of Hanoi puzzle, suppose our goal is to transfer all n disks from peg 1 to peg 3, but we cannot move a disk directly between pegs 1 and 3. Each move of a disk must be a move involving peg 2. As usual, we cannot place a disk on top of a smaller disk."

The solution involves the following steps:

  1. Move n-1 disks from peg 1 to peg 3 (requires Sn-1 steps)

  2. Move the nth disk from peg 1 to peg 2 (requires 1 step)

  3. Move n-1 disks from peg 3 to peg 1 (requires Sn-1 steps)

  4. Move the nth disk from peg 2 to peg 3 (requires 1 step)

  5. Now it takes Sn-1 steps to move the remaining disks from peg 1 to peg 3.

I understand perfectly from 1 to 4 but I do not get the idea of step 5. I will very much appreciate your feedback.

Finally, the recurrence relation is Sn = 3Sn-1 + 2.

Best Answer

Step 5 is the same as Step 1. We move the stack of $n−1$ disks in $S_{n−1}$ (legal) steps. This stack move will also use peg 2 in the process, of course, but we don't spell it out as part of this argument. The larger disks below don't affect or interfere with the movement of smaller disks during the stack move.

Thus the recurrence definition of $S_n$ can be established just by adding the number of moves in the 5 steps.

$$S_n = \overbrace {S_{n-1}}^{\text{step 1}}+\overbrace {1}^{\text{step 2}}+\overbrace {S_{n-1}}^{\text{step 3}}+\overbrace {1}^{\text{step 4}}+\overbrace {S_{n-1}}^{\text{step 5}} = 3S_{n-1}+2$$

You could also observe, perhaps, that $S_1=2$.

Related Question