Tower of hanoi problem., Data Structure & Algorithms

Write an algorithm for getting solution to the Tower's of Hanoi problem. Explain the working of your algorithm (with 4 disks) with appropriate diagrams.


void Hanoi(int n, char initial, char temp, char final)

{     if(n==1)

{ printf("move disk 1 from peg %c to peg%c\n",initial,final);



Hanoi(n-1,initial, final, temp);

printf("move disk %d from peg %c to peg%c\n", n, initial, final);



For n=4, let A, B and C denotes the initial, temp and final peg respectively. Using above algorithm, the  recursive  solution  for  n=4  disks  comprises  of  the  following 15 moves:

1549_Hanoi problem.png

Posted Date: 7/10/2012 3:08:47 AM | Location : United States

Related Discussions:- Tower of hanoi problem., Assignment Help, Ask Question on Tower of hanoi problem., Get Answer, Expert's Help, Tower of hanoi problem. Discussions

Write discussion on Tower of hanoi problem.
Your posts are moderated
Related Questions

Comp are two functions n 2    and  2 n  / 4  for distinct values of n.   Determine When s ec on d function b ec om es l a r g er th an f i r st functi

1. In computer science, a classic problem is how to dynamically store information so as to let for quick look up. This searching problem arises frequently in dictionaries, symbol t

what is frequency count with examble? examble?

Q. Convert the following given Infix expression to Postfix form using the stack function: x + y * z + ( p * q + r ) * s , Follow general precedence rule and suppose tha

Implement multiple stacks in a single dimensional array. Write algorithms for various stack operations for them.

Double ended queues are implemented along doubly linked lists. A doubly link list can traverse in both of the directions as it contain two pointers namely left pointers and righ

Write the algorithm for Binary search. Also apply this algorithm on the following data. 22, 44, 11, 88, 33, 55, 77, 66

What is a linear array? An array is a way to reference a series of memory locations using the similar name. Every memory location is shown by an array element. An  array elemen

The controversy of RISC versus CISC never ends. Suppose that you represent an advocate for the RISC approach; write at least a one-page critic of the CISC approach showing its disa