3. Tower of Hanoi orTowers of Hanoi 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.
4. • The objective of the puzzle is to move the entire stack to
another rod, obeying the following rules:
Only one disk can 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 can be placed on top of a smaller disk than itself(ie. You can not put the
bigger disc on smaller one but you can put smaller disc on bigger one disc.)
5.
6. For simplicity, suppose there were just 3 disks, and
we’ll refer to the three tower as , tower1 , tower2 and
tower 3...
Since we can only move one disk at a time, we move the top disk from tower1 to tower3.
7. We then move the top disk from tower1 to tower 2.
13. SEVENTH MOVE:
and we’re done!
But The problem gets more difficult as the number of disks increases...
14.
15. Step 1 − Move n-1 disks from source to aux
Step 2 − Move nth disk from source to dest
Step 3 − Move n-1 disks from aux to dest
Algorithm
16. The minimal number of moves required to solve a Tower
of Hanoi puzzle is 2n − 1,
where n is the number of disks.
17. Let’s see how many moves” it takes to solve this problem,
as a function of n, the number of disks to be moved.
n Number of disk-moves required
1 1
2 3
3 7
4 15
5 31
...
i 2i-1
64 264-1 (a big number)