Question

In: Computer Science

Consider the following variants of the Towers of Hanoi. For each of variant, describe an algorithm...

Consider the following variants of the Towers of Hanoi. For each of variant, describe an algorithm to solve it 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. In all the following variants, you are not allowed to put a bigger disk on top of a smaller disk. Consider the disappearing Tower of Hanoi puzzle where the largest remaining disk will disappear if there is nothing on top of it. The goal here is to get all the disks to disappear and be left with three empty pegs (in as few moves as possible). Provide an upper bound, as tight as possible, on the number of moves your algorithm uses.

For reference, the original Hanoi function is written as so:

Hanoi(n, src, dest, temp){

if(n > 0) {

   Hanoi(n-1, src, temp, dest)

   Move disk n from src to dest

   Hanoi(n − 1, temp, dest, src)

}

}

Solutions

Expert Solution

In this variation, if the largest remaining disk becomes free with nothing on top, it disappears.

The goal is to make the whole tower disappear. For instance, an = 0 when n ≤ 1 (with either no disks or one free disk). With two disks, once the smallest is moved, the largest disk becomes free and disappears, so the smallest, being now the largest remaining free disk, will follow, resulting in a2 = 1. Similarly, it is not hard to see that a3 = 2.

The optimal solution can be derived as follows:

To free the largest disk, one must move the second largest, which as illustrated for the case of n = 2, will also disappear. Observe that no disks can disappear prior to the largest. Therefore, we first transfer n−2 disks to some peg, then move the second largest disk to another, hence freeing two disks for two disappearing at once, and finally repeat the solution for the remaining n − 2 disks.

Disappearing(n, x, y, z)

if n > 1

then Hanoi(n − 2, x, z, y)

Move(1, x, z)

disks n and n − 1 disappear

Disappearing(n − 2, y, x, z)


Related Solutions

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 forbidden to move any disk directly between peg 1 and peg 2, and every move must involve (the...
Program a solver for the Towers of Hanoi problem presented below. Submit the following to canvas:...
Program a solver for the Towers of Hanoi problem presented below. Submit the following to canvas: Hanoi.java, Driver.java (contains your main method). This is an individual project. Students may discuss solutions to the problem but may not share code with one another. I will discuss this project during our next lecture. Rules: a) There are three Pillars (Pillar1, Pillar2, Pillar3). b) There are N number of disks of increasing size (disk size is indicated by an integer). c) At the...
Write a java program to solve Towers of Hanoi with the condition that there are "m"...
Write a java program to solve Towers of Hanoi with the condition that there are "m" number of rods and "n" number of disks. Where m >= 3 and n >=1.
There is a famous puzzle called the Towers of Hanoi that consists of three pegs and...
There is a famous puzzle called the Towers of Hanoi that consists of three pegs and n circular disks, all of different sizes. The disks start on the leftmost peg, with the largest disk on the bottom, the second largest on top of it, and so on, up to the smallest disk on top. The goal is to move the disks so that they are stacked in this same order on the rightmost peg. However, you are allowed to move...
JAVA Program a solver for the Towers of Hanoi problem presented below. Submit the Following: Hanoi.java,...
JAVA Program a solver for the Towers of Hanoi problem presented below. Submit the Following: Hanoi.java, Driver.java (contains your main method). Rules: a) There are three Pillars (Pillar1, Pillar2, Pillar3). b) There are N number of disks of increasing size (disk size is indicated by an integer). c) At the start, all disks are stacked on one of the pillars. d) At no point can a disk of larger size be placed above a disk of smaller size (including the...
towers of hanoi c++ program using stacks and singly linked lists.
towers of hanoi c++ program using stacks and singly linked lists.
i want it in C++.You will solve the Towers of Hanoi problem in an iterative manner...
i want it in C++.You will solve the Towers of Hanoi problem in an iterative manner (using Stack) in C++(using data structure). Note: you have to solve for N number of disks, 3 Towers (Stacks). Do not use recursion. For better understanding play the game at least once. Link:https://www.mathsisfun.com/games/towerofhanoi.html
Write a MIPS assembly language procedure that implements the Towers of Hanoi recursive function given the...
Write a MIPS assembly language procedure that implements the Towers of Hanoi recursive function given the following declaration: void towers(int n, char source, char dest, char spare); The function outputs a message describing each move. The source, destination, and spare poles are indicated with a character identifier of your choosing ('A', 'B', 'C' are common). Write a MIPS assembly language program that demonstrates the Towers of Hanoi procedure. Your program should ask the user for the number of disks. The...
How many moves are required to solve the Towers of Hanoi problem when we have 3...
How many moves are required to solve the Towers of Hanoi problem when we have 3 disks? Group of answer choices 5 6 8 4 7 After the following statements execute, what item is at the front of the queue? QueueInterface<String> zooDelivery = new LinkedQueue<>(); zooDelivery.enqueue("lion"); zooDelivery.enqueue("tiger"); zooDelivery.enqueue("cheetah"); String next = zooDelivery.dequeue(); next = zooDelivery.dequeue(); zooDelivery.enqueue("jaguar"); zooDelivery.enqueue("cat"); Group of answer choices "lion" "tiger" "cheetah" "jaguar" "cat" When a recursive method does not include a base case, calling the method results...
Describe the variants of the direct instruction model and assess the advantages and limitations of each...
Describe the variants of the direct instruction model and assess the advantages and limitations of each variation.     How Do Students Learn and Transfer Concepts? EDUCATIONAL PSYCHOLOGY 11 EDITION BY SLAVIN
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT