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

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...
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...
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
Design a variant of the hybrid merge-join algorithm for the case where both relations are not...
Design a variant of the hybrid merge-join algorithm for the case where both relations are not physically sorted, but both have a sorted secondary index on the join attributes.
Consider the following variant of theBertrand Model of Duopoly. Suppose there are two firms producing the...
Consider the following variant of theBertrand Model of Duopoly. Suppose there are two firms producing the same good and they simultaneously set prices for their product. If firm i sets a price piand firm j sets a price pj, the total quantity demanded for firm i’s product is given by:qi= 10 –pi+ ½ pjEach firm produces exactly the qidemanded by the market. Bothfirms have the same marginal cost of production: c=4. For example, if a firm produces 5 units it...
Consider the infinitely repeated game with discount factor E[0,1] of the following variant of the Prisoner's...
Consider the infinitely repeated game with discount factor E[0,1] of the following variant of the Prisoner's Dilemma game: Player 2 L C R T (6, 6) (-1, 7) (-2, 8) Player 1 M (7, -1) (4, 4) (-1, 5) B (8, -2) (5, -1) (1,1) A) For which values of the discount factor E[0,1] can the players support the pair of actions (M, C) played in every period? B) For which values of the discount factor E[0,1] can the players...
Consider the following variant of two-finger morra, where Alice picks an action a ∈ {1, 2}...
Consider the following variant of two-finger morra, where Alice picks an action a ∈ {1, 2} and Bob picks an action b ∈ {1, 2}. Bob pays Alice $(a × b) if a + b is even, and Alice pays Bob $(a × b) if a + b is odd. Note that the payoff is different than that in the example we used in class. 1) If Alice plays 1 finger with probability p and 2 fingers with probability 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT