Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the towers of Hanoi game, how do we know that we have the optimal algorithm for solving it? I thought about this and it seemed like any deviation from the standard strategies would be putting you back a step, but I had no idea how to demonstrate this rigorously.

All I know is that the proof involves the Lucas correspondence between the Hanoi graph and the odd coefficients in Pascal's triangle. How is Pascal's triangle turned into a graph? I assume the coefficient are the vertices, but I don't see how you form the edges?

I was also wondering how to generalize the strategy to n discs and k rods because it seems like this correspondence argument wouldn't really work in the general case.

Basically, I am wondering how the odd coefficients of the Pascal triangle are turned into a graph and whether or not there is a similar method to find and prove optimal strategy when we increase the number of rods.

share|cite|improve this question
Wikipedia has quite good article about Towers of Hanoi. – falagar Aug 17 '10 at 13:36
I read the wikipedia article, but it doesn't address proving that these strategies solve the puzzle in the minimal number of steps an doesn't address generalizing the problem to more than 3 rods. – WWright Aug 17 '10 at 15:14
Finding the worst strategy (free of internal cycles) is much more fun ;-) – Stéphane Gimenez Oct 3 '11 at 0:02
up vote 11 down vote accepted

I will address your first question, but not the one for larger number of rods; as far as I know, it's still generally wide open what the optimal strategy might be even for $4$ rods and a smallish number of disks.

To show the optimal strategy for $n$ disks in $3$ rods is the "usual" one, you can do it by induction (which yields a recursive solution). I'm sure there are other ways of proving it, perhaps with Lucas numbers as you suggest.

Clearly, the optimal strategy with $n=1$ is to simply move the disk directly.

Assume you already have the optimal strategy for moving $k$ disks. To move $k+1$ disks, you need to move the largest disk from the initial rod to the terminal rod, but that is the only time it needs to move (it cannot help you with the other disks, since it must lie at the bottom at any given time, so any other moves only require further moves in the end); to move the bottom ($k+1$)st disk from the initial rod $I$ to the terminal rod $T$, you must first move the top $k$ disks out of the way; this requires moving the $k$ disks from the initial rod $I$ to the auxiliary rod $A$, and the optimal way of doing this is the optimal strategy you know for $k$ disks. Then you move the $k+1$st disk, and then you want to move the remaining $k$ disks from the auxiliary rod to the terminal one in as few moves as possible (the optimal way). So the optimal strategy for $k+1$ disks is to move the top $k$ using the optimal strategy for $k$ from $I$ to $A$, then move the largest disk from $I$ to $T$, then move the top $k$ disks using the optimal strategy for $k$ from $A$ to $T$.

By keeping track of the actual number of moves needed at each step, you can give the number. For $n=1$, the number is $1=2^1-1$. Assume that moving $k$ disks requires $2^k-1$ moves in the optimal strategy. The optimal strategy for $k+1$ described above takes $(2^k-1) + 1 + (2^k-1) = 2^k+2^k - 1 = 2^{k+1}-1$ steps; thus, the optimal solution for $n$ disks and $3$ rods requires $2^n-1$ moves.

(This does not generalize easily to more than $3$ rods for presumably obvious reasons).

A bit more interesting is trying to prove that the non-recursive solution gives an optimal solution; this solution only requires you to remember the last disk you moved at any given time (the recursive solution is more memory intensive, of course). Number the rods $0$, $1$, and $2$. We have three rules:

  1. Never move the same disk twice in succession.
  2. You can only move a disk from the top of one rod to the top of another rod.
  3. Moving a disk from rod $i$ to rod $j$ is only valid if $i\neq j$, and either rod $j$ is empty or the top disk in rod $j$ is larger than the top disk in rod $i$.

With these rules, the non-recursive algorithm has two simple steps:

  • If you are moving the disk from rod $i$, and the two other rods are valid destinations, then move it to rod $i+1\mod 3$. Otherwise, move it to the only valid destination.
  • If no move is possible, stop. Otherwise, continue.

This process will solve the puzzle with $3$ rods in the minimum number of moves.

share|cite|improve this answer
It didn't occur to me to induct on the recursive strategy. It seems kind of obvious now that I see it written out. I was hoping the graph theory methods would generalize naturally, but this doesn't seem to be the case. Thanks. – WWright Aug 17 '10 at 16:46
The optimal strategy with n=0 is to do nothing, which makes it an even better base case. – starblue Aug 17 '10 at 19:24
Fair enough! (-: – Arturo Magidin Aug 17 '10 at 19:49
Here's an equivalent way to express the non-recursive algorithm, possibly simpler since it lacks rules. (1) Move the smallest disk "forward", i.e. from rod $i$ to rod $i+1$ mod 3 (or, with the rods in a circle, move it clockwise); (2) if there are two empty rods, stop, you're done; (3) Make the only move possible that doesn't involve the smallest disk; (4) go to (1). – Larry Denenberg Oct 27 '10 at 20:34

In general, with n rods and n disks, the problem is equivalent to finding a Hamiltonian path on an n-hypercube. There is no proven optimal strategy known for 4 rods. You could also read the MathWorld article which has references for quite a few papers on the subject.

share|cite|improve this answer
Thanks. I wasn't aware of the relationship between the problem and Hamiltonian paths on hypercubes. – WWright Aug 17 '10 at 16:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.