Question

Refer the "Tower oh Hanoi" concept 1. What is the minimum number of steps if there...

Refer the "Tower oh Hanoi" concept

1. What is the minimum number of steps if there are 1, 2, 3, 4, or more disks? Try and solve the puzzle and fill in the table.

1 1
2 3
3 7
4 15
5 ?
6 ?
7 ?
8 ?

2. Write an explicit formula for the minimum number of steps required for the puzzle? Use H(n) = ? where n is the number of disks

3. What would be the best ADT to use for the posts in the puzzle? Why is that data structure best?

4. What would be the base case (n = 1) of this problem if a recursive solution was employed? Use three of the ADTs from the previous question for storage. The three posts are labeled A, B, C. Post A is the the starting post and Post C is the ending post. Write the answer in in pseudo code.

5. What are the rest of the cases given the base case?

if (n == 1)

            disk = A.top()

            A.pop()

            C.push(disk)

C++

Homework Answers

Answer #1

SOLUTION-

1. What is the minimum number of steps if there are 1, 2, 3, 4, or more disks? Try and solve the puzzle and fill in the table.

1 1
2 3
3 7
4 15
5 31
6 63
7 127
8

255

2. Write an explicit formula for the minimum number of steps required for the puzzle? Use H(n) = ? where n is the number of disks

We can derive a common pattern using values in the above table;

for number of disks (n=1), we have number of steps: 1 (2^1-1)

for number of disks (n=2), we have number of steps: 3 (2^2-1)

for number of disks (n=3), we have number of steps: 7 (2^3-1)

for number of disks (n=4), we have number of steps: 15 (2^4-1)

for number of disks (n=5), we have number of steps: 31 (2^5-1)

for number of disks (n=6), we have number of steps: 63 (2^6-1)

for number of disks (n=7), we have number of steps: 127 (2^7-1)

for number of disks (n=8), we have number of steps: 255 (2^8-1)

Thus,formula: H(n)= 2^n - 1; where n=number of disks

3. What would be the best ADT to use for the posts in the puzzle? Why is that data structure best?

So the Best data structure for the posts in this puzzle is a stack. Stack is used to  follows convention of first in last out(FILO). In this puzzle, we have three rings arranged in ascending order from top to bottom residing on a tower(stack) at any given point of time. The largest ring is placed first on the post and removed last following the convention of stack. Similarly, the smallest ring is placed last on top of other rings and removed first before any other ring thus, following he convention of a stack. Thus, stack is the best data structure.

4. What would be the base case (n = 1) of this problem if a recursive solution was employed? Use three of the ADTs from the previous question for storage. The three posts are labeled A, B, C. Post A is the the starting post and Post C is the ending post. Write the answer in in pseudo code.

If we follow recursive appeoach, the best case scenario would when our problem is reduced to only 1 disk out of n disks. This means we need to transfer only one disk from our source to destination. Using the formula we derived above, this can be achieved in 1 step only (2^1-1). This would be the case when we would want to move our largest disk whoch is being kept at the bottom of the source to our destination. If we wish to track the movement of every disk form one tower to another we can write the best case as follows:

void towerOfHanoi(int n, char source, char auxillary, char destination){

if ( n == 1){

disk=source.top;

source.pop();

destination.push(disk);

cout<<"Move disk 1 from "<<source<<" to "<<destination;

         return;

}

}

5. What are the rest of the cases given the base case?

Rest of the function includes recursive calls to the function towerOfHanoi with no of disks equals one less than the given number as 1 dis is already shifted to its correct place.

towerOfHamoi(n-1,source,destination,auxillary);

cout<<"Move disk 1 from "<<source<<" to "<<destination;

towerOfHanoi(n-1,auxillary,source,destination);

In this algorithm we are calling the funtion towerOfHanoi recursively. Base case if achieved when we have already one disk left to be moved. This is shown above. For rest of the n-1 disks, we will first move them from source to destination using auxillary rod. Once n-1 disks are moved to auxillary rod, we can easily move the last remaining disk in source to destination. We will then recursively repeat our approach considering there are n-1 disks.


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I have a recursive Tower of Hanoi program but don't know how to include the count...
I have a recursive Tower of Hanoi program but don't know how to include the count variable. Could you tell me how? Main.java import java.io.*; import java.util.List; public class Main { //int count = 0; /**There is a stack of N disks on the first of three poles (call them A, B and C) and your job is to move the disks from pole A to pole B without ever putting a larger disk on top of a smaller disk.*/...
LANGUAGE IS C++ 1- A link based getEntry method requires how many steps to access the...
LANGUAGE IS C++ 1- A link based getEntry method requires how many steps to access the nth item in the list? a)n b)n+1 c)n^2 d)n-1 2- When calling the insert or remove methods, what is an disadvantage for the link-based implementation of the ADT List? a)harder to understand b)must shift data c)searching for that position is slower d)takes more memory 3-What is the last step in the insertion process for a linked implementation of the ADT List? a)Connect the new...
1. Given Hexadecimal EDCC16 Detail steps are required. 1) What is the binary representation? 2) What...
1. Given Hexadecimal EDCC16 Detail steps are required. 1) What is the binary representation? 2) What is the negation of EDCC in HEX? 3) Convert it to decimal number if this is a 2s-complement signed binary representation in 16- bit register 4) Convert it to decimal number if this is an unsigned binary representation in 16-bit 2. Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3, B’s base address is in $S4, C’s...
We are given a sequence of numbers: 1, 3, 5, 7, 9, . . . and...
We are given a sequence of numbers: 1, 3, 5, 7, 9, . . . and want to prove that the closed formula for the sequence is an = 2n – 1.          What would the next number in the sequence be? What is the recursive formula for the sequence? Is the closed formula true for a1? What about a2? What about a3? Critical Thinking How many values would we have to check before we could be sure that the...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n ==...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0)    return 0; else    return n * f(n - 1); } A. 120 B. 60 C. 1 D. 0 10 points    QUESTION 2 Which of the following statements could describe the general (recursive) case of a recursive algorithm? In the following recursive function, which line(s) represent the general (recursive) case? void PrintIt(int n ) // line 1 { // line 2...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
Part 1: Use the following steps to create a standard normal in StatKey and answer the...
Part 1: Use the following steps to create a standard normal in StatKey and answer the following questions about the variable Z. Go to http://www.lock5stat.com/StatKey/ Click on Normal (This is located in the theoretical distributions section) Notice in the right hand corner StatKey has a mean of 0 and standard deviation of 1 as default Notice in the left hand corner are the usual left, right and 2 tail options these will be helpful in the problems below For each...
ECOMMERCE - Profit went down 75. Expense went down 22. What did Revenue do? - Choose...
ECOMMERCE - Profit went down 75. Expense went down 22. What did Revenue do? - Choose the best match: 1. cannibalization 2. click n mortar 3. International Dollar Power 4. dynamic catalog A. NYPOST.COM is reducing the number of physical newspapers sold by the NY POST. B. product catalogs that use databases to store & display information C. Since most international trade is done in dollars or thru US commercial banks, the US can limit the amount of trade that...
~ Part I: Rules ~ Dominance and Recessive Traits (1.) What is the chromosome number (“n”)...
~ Part I: Rules ~ Dominance and Recessive Traits (1.) What is the chromosome number (“n”) for the dragons? (2.) Which trait(s) exhibit incomplete dominance? (3.) What does it mean for a trait to be incompletely dominant? (4.) No allelic combination is described as being heterozygous recessive. Why do you think this is the case? Some Traits are Sex-linked (5.) Which dragon trait(s) is/are sex-linked? (6.) How do sex-linked traits differ from autosomal traits? Color and Lethal Combinations (7.) Describe...
Computer Graphics/Web-GL questions Question 26 Consider three vectors, l, n, and v, which are direction of...
Computer Graphics/Web-GL questions Question 26 Consider three vectors, l, n, and v, which are direction of in ray, normal of the surface, and out ray, respectively. If the viewer is distant (i.e. at infinite), which of the following is constant? l n v none of these three Question 27 Since the sphere is not an object supported within WebGL, so we will generate approximations to a sphere using_________ through a process known as recursive subdivision. Which of the following is...