Explain the tower of hanoi problem

Assignment Help Programming Languages
Reference no: EM13935822

1879_toi.png

In order to attempt to move the disks from peg 1 to peg 3, develop an algorithm that will print the precise sequence of peg-to-peg disk transfers.

Solve the problem with recursion in mind, it immediately becomes tractable. Moving n disks can be viewed in terms of moving only n-1 disks as follows:

a) Move n -1 disks from peg 1 to peg 2, using peg 3 as a temporary holding area.

b) Move the last disk from peg 1 to peg 3.

c) Move n -1 disks from peg 2 to peg 3, using peg 1 as a temporary holding area.

The process ends when the last task involves moving n = 1 disk (i.e., the base case). This task is accomplished simply by moving the disk, without the need for a temporary holding area.

Write a javascript to solve the problem of the Towers of Hanoi. Allow the end user to enter the number of disks in a text field. Use a recursive tower function with four parameters:

a) The number of disks to be moved.

b) The peg on which the disks are initially threaded.

c) The peg to which the stack of disks is to be moved.

d) The peg to be used as a temporary holding area.

Program should display in a <textarea> the precise instructions it will take to move the disks from the starting peg to the destination peg. For example, to move a stack of three disks from peg 1 to peg 3, your program should display the following series of moves:

1 -> 3 (i.e. movement from peg 1 to peg 3.)

1-> 2

3 -> 2

1-> 3

2 -> 1

2 -> 3

1 -> 3

Reference no: EM13935822

Questions Cloud

Understand and apply leadership concepts to your work : Do not merely summarise each week's readings. Instead, explain how the readings, (or class activities, discussions), films, and your observations have helped you understand and apply leadership concepts to your work
E-commerce a technique of modern business : E-business or E-commerce is a technique of modern business, which means electronic commerce that helps any organization buying and selling products online. In other word, we can say that it helps the organization in various ways, such as-:
Describe how bach could use a long strangle to hedge : Describe how Bach could use a long strangle to hedge its possible dirham positions. What is the tradeoff involved in using a long strangle versus a long straddle to hedge the positions?
Wireless network coverage and other issues : In this assignment, you will compare and contrast wireless network coverage and other issues involved in the selection of a wireless provider and a mobile ad hoc networks (MANET).
Explain the tower of hanoi problem : Write a javascript to solve the problem of the Towers of Hanoi. Allow the end user to enter the number of disks in a text field. Use a recursive tower function with four parameters:
Determine the expected amount of british pounds : Determine the expected amount of British pounds that you will receive if you use a forward hedge. Determine the expected amount of pounds that you will receive if you do not hedge and believe in purchasing power parity.
Produce a network security plan and demonstrate : Please consider the project case of Lloyds Business School as a MODEL CASE SCENARIO. However, your group can choose to work on it, if they wish to. Furthermore, you are encouraged to select and work on any organisational network security project (..
Analyse the effectiveness of leadership : Task: Critically analyse the effectiveness of leadership portrayed in the movie you have selected using the framework for assessing leadership effectiveness
Define similarities in the structure of e. coli and hiv : Structural differences can simply be addressed by distinguishing the physical differences between E. Coli and HIV. Characteristics that are commonly used to classify or distinguish the differences between the microorganisms may also be presented.

Reviews

Write a Review

Programming Languages Questions & Answers

  Create a program to draw image of archery target

Assume that you have been hired to produce a program which draws the image of the archery target-or, if you prefer commercial applications, a logo for national department store.

  Program for class quiz to implement measurable interface

State a class Quiz to implement Measurable interface. A quiz has a score and a letter grade (such as B+).

  Create class for factory workers are paid certain amount

Create class for Factory workers are paid a certain amount for each unit they make and their total pay is the number of units produced times the pay per unit.

  Write program which asks user for names

Write down a program which asks user for names (Prompt user with something like "Enter a name, or q when finished"), assigns new Person (in heap memory) for each of them.

  Program to print a business travel expenses

Write a program to print a business travel expenses attachment for an income tax return.

  How do you rotate say a vector

How do you rotate say a vector = [ 1 2 3 4 5]  to the right [5 1 2 3 4] and if done with the expression again it would result in [4 5 1 2 3].

  Explain the project manuals for python and java

Overview: Understand TCP socket programing by developing a (multi-threaded) Web server. You may use Python, Java, or C++ as the programing language. The project manuals for Python and Java are attached to this document, which have provided partial..

  Create shell script to enter length and width of rectangle

Network client needs you create the shell script which permits the user to enter length and width of rectangle. Perimeter of rectangle is then computed and printed to computer screen.

  Develop the application to show coffee customer orders

Develop the application which shows the total pounds of coffee customer orders, sales tax, and total price of order. Write down the name the solution, project, and form file Jason Coffee Solution, Jason Coffee Project.

  Design function to accept two integer values

Design function named max that accepts two integer values as arguments and returns the value that is the greater of the two. for example if 7 and 12 are passed as arguments to the function the function should return 12.

  Design interactive program using prewritten methods

Design an interactive program that does the following, using the prewritten methods whenever they are appropriate. Prompt the user for and read a library card number, which must be between 1000 and 9999.

  Compare three generations of programming languages

Compare and contrast at least three generations of programming languages. Be sure to include in your discussion: semantics, syntax, and machine dependence.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd