4. Rules
• Only one disk may be moved at a time. Specifically, only the top disk
on any disk on any peg may be moved to any other peg.
• At no time can a larger disk be placed on a smaller disk.
14. Algorithm
Let’s call the three peg BEG(Source), AUX(AUXiliary) and
st(Destination).
1) Move the top N – 1 disks from the Source to AUXiliary tower
2) Move the Nth disk from Source to Destination tower
3) Move the N – 1 disks from AUXiliary tower to Destination tower.
Transferring the top N – 1 disks from Source to AUXiliary tower can
again be thought of as a fresh problem and can be solved in the
same manner.
16. Tower of Hanoi( N= 3)
1. Move from BEG to END
2. Move from BEG to AUX
3. Move from END to AUX
4. Move from BEG to END
5. Move from AUX to BEG
6. Move from AUX to END
7. Move from BEG to END
17. Tower of Hanoi( N= 4)
1. Move from BEG to AUX
2. Move from BEG to END
3. Move from AUX to END
4. Move from BEG to AUX
5. Move from END to BEG
6. Move from END to AUX
7. Move from BEG to AUX
18. Tower of Hanoi( N= 4)
8. Move from BEG to END
9. Move from AUX to END
10. Move from AUX to BEG
11. Move from END to BEG
12. Move from AUX to END
13. Move from BEG to AUX
14. Move from BEG to END
15. Move from AUX to END
In recursive form of algorithm, consider n disks are grouped in two groups. One is single and other is a group of remaining n-1 disks. Now instead of n disks it becomes a problem of 2 disks. The 2 two disks can be transferred in two steps.
Taking 1st disk from Beg to End.
And 2nd disk in two steps. From Beg to Auxiliary and then auxiliary to End.
This method continues till value of n decreases to 2, which is simple base case.