Blog Archives

Towers of Hanoi problem

Introduction :

The Tower of Hanoi (also called the Tower of Brahma or Lucas’ Tower, and sometimes pluralised) is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.

The objective of the puzzle is to move the entire stack to another rod, obeying the following rules:

  • Only one disk may be moved at a time.
  • Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod.
  • No disk may be placed on top of a smaller disk.

With three disks, the puzzle can be solved in seven moves.

Our Lemma:

for  n disks and 3 towers, the number of steps required to transfer the disks from 1  tower to another is 2^n -1.

Proof of our lemma:

Let Q_n denote the minimum number of moves required for transferring n discs from one peg to another.Suppose that there are k+1 discs on peg 1 . We will first transfer the top k discs to peg 3 . This can be done in Q_k moves.
Now we transfer the k+1th disc to peg 2 . One move will be required for this.
Finally we will transfer k discs which are on peg 3 to peg 2 . This will require another m_k moves. Thus the transfer will be done in Q_k+1+Q_k moves which will be equal to Q_{k+1} movesTherefore we have formed a recurrence relation that
Q_{k+1} = 2Q_k + 1

Now we will obtain a general formula for Q_{k+1}


We will multiply both sides of the above relations by 1 , 2 , 2^2 , \cdots 2^{n-2}
we get

Solving this gives us

Q_n=2^{n-1}m_1+1+2+2^2 \cdots 2^{n-2}

Since Q_1=1 ( one move will be required to move )


Q_n = 2^n - 1


Sources :
1. wikepedia ( for the introduction) :