Question

Desbribe tower of Hanoi problem, provide an algorithim for it and analyze the time complexity of...


Desbribe tower of Hanoi problem, provide an algorithim for it and analyze the time complexity of your algorithim.

(only attempt if you can solve thank you)

Homework Answers

Answer #1

Tower of hanoi is a mathematical puzzle which consists of three rods and disks. Initially all the disks are located at first rod , our task is to move the disks to the last rod with  help of auxiliary rod by following certain rules:-

(i) One disk can be moved at a time.

(ii) Only top disk can be moved.

(iii) Larger disk can't sit on smaller disk.

Suppose we have 2 disks. we first move the smaller top disk to the auxiliarly peg. Move the bigger disk to destination and then finally move smaller peg which was on auxiliary rod to destination rod.

1 − Move m-1 disks from source to aux

2 − Move mth disk from source to dest

3 − Move m-1 disks from aux to dest

Algorithm:-

START
Function Hanoi(disk, src, dest, auxil)

   IF disk == 1, THEN
      move disk from src to dest             
   ELSE
      Hanoi(disk - 1, src, auxil, dest)     
      move disk from src to dest          
      Hanoi(disk - 1, auxil, dest, src)     
   END IF
   
END Function
STOP

Time complexity for recursive tower of hanoi approach is exponential and it is O(2n).

DON'T FORGET TO HIT LIKE.

THANKS BY HEART.

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.*/...
Analyze the space and time complexity for the linear bounded automaton that accepted the set of...
Analyze the space and time complexity for the linear bounded automaton that accepted the set of squares.
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...
In all algorithms, always prove why they work. ALWAYS, analyze the complexity of your algorithms. In...
In all algorithms, always prove why they work. ALWAYS, analyze the complexity of your algorithms. In all algorithms, always try to get the fastest possible. A matching M = {ei} is maximal if there is no other matching M' so that M ⊆ M' and M /= M' . Give an algorithm that finds a maximal matching M in polynomial time. The algorithm should be in pseudocode/plain English. Provide the complexity of the algorithm as well.
Describe an algorithm to solve the variant of the Towers of Hanoi in as few moves...
Describe an algorithm to solve the variant of the Towers of Hanoi in as few moves as possible. Prove that your algorithm is correct. Initially, all the n disks are on peg 1, and you need to move the disks to peg 2. You are not allowed to put a bigger disk on top of a smaller disk. 1. Suppose you are only allowed to move disks from peg 0 to peg 1, from peg 1 to peg 2, or...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm that is executed most frequently. Express the number of times it is executed as a function of N. Convert this expression into the Big-O notation. A. For each of the three fragments of code, what is its worst-case time complexity, in the form "O(…)". (Use the given solution to the first problem as a model)                 //----------------- This is a sample problem – solved ------...
Given the recursive bubble sort algorithm, analyze its time complexity in terms of Big O. bubbleSort(A[],...
Given the recursive bubble sort algorithm, analyze its time complexity in terms of Big O. bubbleSort(A[], n) { // Base case if (n == 1) return;    // One pass of bubble sort. After // this pass, the largest element // is moved (or bubbled) to end. for (i=0; i<n-1; i++) if (A[i] > A[i+1]) swap(A[i], A[i+1]);    // Largest element is fixed, // recur for remaining array bubbleSort(A, n-1); }
Use QuickSort pivot method, provide time complexity analysis. You go to the market and you see...
Use QuickSort pivot method, provide time complexity analysis. You go to the market and you see that a store selling fruits has baskets filled with fruits for people to take kept right in front of their store. The fruits are delicious and soon you see that there are many baskets with no fruits. To ensure the store can easily replenish baskets with empty fruits, these baskets have to be kept closer to the door. Otherwise the store owner takes his...
With clear example, you will need to do comparative time complexity to solve Minimum Spanning Tree...
With clear example, you will need to do comparative time complexity to solve Minimum Spanning Tree using Greedy Algorithm of Prim and Kruskall with three different Data Structures 1. Weight Matrix   2. Adjacency List 3. Adjacency List with Priority
With regard to multi variable calculus can some explain Strokes Theorem in detail. Thank you. Provide...
With regard to multi variable calculus can some explain Strokes Theorem in detail. Thank you. Provide an example problem and solve too thanks!
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT