
Write an algorithm to find solution to the Towers of Hanoi problem?  
asked  1126 views  1 answers.  
Algorithm to find solution to the Towers of Hanoi. Working and Explanation of the algorithm for 3 disk with diagram.  
AlgorithmSolutionHanoiTowerC  
 
Add comment 
0
 Let us take A, B and C are needles. n is number of disks.
The aim of the tower of Hanoi problem is to move the initial n different sized disks from needle A to needle C using a temporary needle B.
The rule is that no larger disk is to be placed above the smaller disk in any of the needle while moving or at any time, and only the top of the disk is to be moved at a time from any needle to any needle. We could formulate a recursive algorithm to solve the problem of Hanoi to move n disks from A to C using B as auxiliary. Step 1: If n=1, move the single disk from A to C and return, Step 2: If n>1, move the top n1 disks from A to B using C as temporary. Step 3: Move the remaining disk from A to C. Step 4: Move the n1 disk disks from B to C, using A as temporary. If we implement this algorithm in a C language program,
Now let us workout the output when n=3.The output will be as follows: Move disk 1 from needle A to needle C Move disk 2 from needle A to needle B Move disk 1 from needle C to needle B Move disk 3 from needle A to needle C Move disk 1 from needle B to needle A Move disk 2 from needle B to needle C Move disk 1 from needle A to needle C  
 
move disk 1 from needle A to C move disk 2 from A to B move disk 1 from needle C to B move disk 3 from A to C move disk 1 from needle B to A move disk 2 from B to C move disk 1 from needle A to C move disk 4 from A to B move disk 1 from needle C to B move disk 2 from C to A move disk 1 from needle B to A move disk 3 from C to B move disk 1 from needle A to C move disk 2 from A to B move disk 1 from needle C to B  Rathiga Karunanithi 5 years ago Add comment 
Post Your Answer Here :
Output for 4 disk tower of Hanoi?  Rahul526 5 years ago