Tower of Hanoi
Tower of Hanoi
Recursive Algorithms:
1. Towers of Hanoi:
.
.
.
Consider there are three towers A, B, C and there will be three disks present
in tower A. Consider C as destination tower and B as intermediate tower. The
steps involved during moving the disks from A to B are
Step 1: Move the smaller disk which is present at the top of the tower
A to C.
Step 2: Then move the next smallest disk present at the top of the tower A to
B.
Step 3: Now move the smallest disk present at tower C to tower B
Step 4: Now move the largest disk present at tower A to tower C
Step 5: Move the disk smallest disk present at the top of the tower B
to tower A.
Step 6: Move the disk present at tower B to tower C.
Step 7: Move the smallest disk present at tower A to tower C
In this way disks are moved from source tower to destination tower.
t(n)=1; if n=0
=2t(n-1)+2 if n>=1
Solve the above recurrence relation then the time complexity of towers of Hanoi is
O(2^n)