answersLogoWhite

0


Best Answer

This algorithm reads the value of number of discs and prints the move that are to be done for playing towers of hanoi.

Pre: n is a positive integer which carries the value of number of discs.

Post: prints the moves that are to be done for transferring discs in ascending order in another peg

1.initialize value of n(positive integer greater than 1)

2.moves = pow(2,disk)-1

3.if(n=1)

i) moves disk from "from" to "to"

4. end if

5. else

i)hanoi(n-1,from,aux,to)

ii) moves disc from "from" to "to''

iii) hanoi(n-i,from,aux,to)

6.end else

7. prints the moves

end towers_of_hanoi

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

It can be solved with or without recursion, check the attached link.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

a

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the solution of towers of hanoi problem?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is a proposed solution solution to a scientific problem?

Hypothesis


Move 5 disks in the tower of hanoi algorithm?

/* tower of hanoi using recursion */ #include<stdio.h> int main(void) { unsigned int nvalue; char snvalue = 'L' , invalue = 'C' , dnvalue = 'R' ; void hanoi(unsigned int , char , char , char); printf(" enter number of disks : "); scanf("%u",&nvalue ); printf("\n\ntower of hanoi problem with %d disks \n ", nvalue )" hanoi(nvalue , snvalue , invalue , dnvalue ); printf("\n"); return 0 ; } void hanoi(unsigned n , char snd1 , char ind1 , char dnd1 ) { if(n!=0) { /* move n-1 disks from starting to intermadiate needles */ hanoi(n-1 , snd1 , dnd1 , ind1 ); /* move disk n from start to destination */ printf("move disk %d from %c to %c\n ", n , snd1 , dnd1); /* move n-1 disks from intermediate to destination needle */ hanoi(n-1 , ind1 , snd1 , dnd1 ); } }


How would you design an algorithm for reversing two adjacent entries on a stack if you were given three stacks and you were only allowed to move entries one at a time from one stack to another?

Research Towers Of Hanoi http://en.wikipedia.org/wiki/Tower_of_Hanoi You will find your answer


What is a step by step solution of a programming problem?

An algorithm.


What is an organized way of solving a problem?

When solving a problem it can be beneficial to go about it in an organized fashion. Start by assessing the problem, brain storm solutions and once a solution is identified, create a detailed plan to implement the solution.

Related questions

What is the nth term for the towers of hanoi?

2n-1


What are the instructions for the towers of hanoi on your maths for 5 discs?

010001010001011111100010100010101010111100110011100111000101001100 In binary


What is the name of the test with 4 rings shown in 'Rise of the Planet of the Apes'?

Towers of Hanoi.


How long would it take to the hanoi puzzle with 6 7 8 discs?

For any n-disc version of the Tower of Hanoi, the optimum solution for the puzzle takes a minimum of 2n-1 moves. In the case of 6, 7, 8-sized Towers of Hanoi, the puzzle would take: 26-1 = 63, 27-1 = 127, 28-1 = 255 moves.


Towers of hanoi?

Putting a question mark after the name of a game or puzzle does not make it a sensible question.


How can you solve the tower of hanoi?

1. Write mathematical analysis for recursive algorithms. Solve Tower of Hanoi Problem and analyze it.


Grey humpreys tower of hanoi problem step by step explanation?

Can I please have the steps, sketch and formula for the tower of hanoi


What is Towers of hanoi?

The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower, and sometimes pluralized) is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod.


How much is the average rental rate of a furnished two bedroom apartment at Sky City Towers Hanoi?

The rental price of high ranking apartments in Hanoi is going down this year. At this time, rate of furnished 2 bedroom apartment at Sky City Towers - 88 Lang Ha is about 1000 - 1200 USD per month


Why do all of the guns in far cry 3 say they need 96 more radio towers to unlock?

I'm having the same problem. Does anyone know a solution?


What did edouard lucas discovered in 1883?

Tower of Hanoi puzzle game - mathematical problem


What is the formula for the towers of Hanoi?

im not sure but it could be double it plus one? if you find out can you please answer the question thanks The answer is (2^n) - 1 where n is the number of disks