Since this is a recursive approach so,it is quite difficult to understand this by just reading the algorithm so,let's take an example to have a better idea of the solution. At last, we will make another recursive call to transfer all the disks from auxiliary pole to destination pole with the help of source pole.If the number of disks in the source pole is left 1 then transfer it to destination pole.This will be handled through base case.First of all, we will make a recursive call to transfer all the disks from source pole to auxiliary pole with the help of destination pole except the last disk.A larger disk can't be placed on a smaller disk.A disk can only be moved if it is the uppermost disk in the pole.There are some rules which needs to be followed at the time of solving this puzzle. The objective of the puzzle is to move all the disks from one pole (source pole) to another pole (destination pole) with the help of the third pole (auxiliary pole). ![]() The puzzle starts with the disk in ascending order of size in one pole, the smallest at the top. It consists of three poles and a number of disks of different sizes which can slide onto any poles. We will get started with Tower Of Hanoi Problem now. Time & Space Complexity of Iterative Approach. ![]() ![]()
0 Comments
Leave a Reply. |