1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
oee [108]
3 years ago
12

Prepare a algorithm visualization for the Tower of Hanoi when 4 disks are to be moved from spindle #1 to spindle #3.

Computers and Technology
1 answer:
Setler [38]3 years ago
6 0

Answer:

follwing is the code for Tower of Hanoi for n disks.

#include <iostream>

using namespace std;

void towofhan(int n,char source,char aux,char dest)//function for tower of hanoi..

{

if(n<0)

return ;

   if(n==1)//base case.

   {

       cout<<"Move disk 1 from "<<source<<" to spindle "<<dest<<endl;

       return;

   }

   towofhan(n-1,source,dest,aux);//recursive call.

   cout<<"move disk "<<n<<" from "<<source<<" to spindle "<<dest<<endl;

   towofhan(n-1,aux,source,dest);//recursive call.

}

int main() {

   int n=4;

   towofhan(n,'1','2','3');//function call.

   return 0;

}

Explanation:

If there is only 1 disk then we have to move the disk from source to destination.

Then after that we will apply recursion to solve the problem.

We have to work on only nth disk else will be done by the recursion.

First call recursion to move n-1 disks from source to auxiliary.

Then move nth disk from source to destination spindle.

Now move n-1 disks that are on the auxiliary spindle to destination spindle.

You might be interested in
What is the final value of the string output given the following code fragment? int counter = 0; int num = 0; string output = ""
swat32

int counter = 0;

int num = 0;

string output = "";

while (counter < 3) {

num = num * 1;

counter = counter + 1; }

output = Convert.ToString(num);

Output:

Counter = 0

num = 0 * 1 - - > num = 0

Counter = 1

num = 0 * 1 - - > num = 0

Counter = 2

num = 0 * 1 - - > num = 0

Counter = 3 (break)

num = 0

output = "0"

3 0
4 years ago
True false) keybord has two shift keys.​
deff fn [24]

Answer:

True, looking at 'em right now!

Explanation:

8 0
4 years ago
Alan is developing a business impact assessment for his organization. He is working with business units to determine the maximum
jekas [21]

Answer:

A. Recovery time objective (RTO)

Explanation:

The recovery time is defined as the maximum length of time require to recover a system or any network from the failure.

Hence, to determine the recovery time of the function, one can use the RTO.

7 0
3 years ago
What is a variable? Why is it helpful in programming?
Komok [63]

Answer:

Variables can represent numeric values, characters, character strings, or memory addresses. Variables play an important role in computer programming because they enable programmers to write flexible programs. Rather than entering data directly into a program, a programmer can use variables to represent the data.

Explanation:

3 0
3 years ago
In relation to data science,advances in technology has made it more feasible to do what
Reika [66]
In recent years data science has become less and less about the data itself, and more about the technology and tools used to interact with it. Advanced solutions like AI, machine learning and robust analytics tools make it possible not just to process and understand massive stores of information but at unprecedented speeds.
3 0
3 years ago
Other questions:
  • Who will win the premier league
    9·2 answers
  • A short-circuit evaluation is where each part of an expression is evaluated only as far as necessary to determine whether the en
    14·1 answer
  • Which of the following statement is most accurate? A. A reference variable is an object. B. A reference variable refers to an ob
    6·1 answer
  • Which command is used to combine two or more cells together into one cell?
    14·2 answers
  • One day you tap your smartphone screen to turn it on, and nothing happens. It appears to be turned off and will not turn on. Wha
    12·2 answers
  • Which student's strategy likely found the most academic success?
    6·1 answer
  • What is the current in a circuit that uses 120V and has 1200W of power?
    6·1 answer
  • 4. Each mobile device described in this chapter requires that the user have a/an ____________________ associated with services o
    5·1 answer
  • Which option describes a balanced slide?
    11·1 answer
  • What is used for risk response control?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!