Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the Hanoi tower program again. We discussed how to write a function to

ID: 3803577 • Letter: C

Question

Consider the Hanoi tower program again. We discussed how to write a function to solve the Hanoi tower problem in an earlier class. Hanoi tower problem: there are three poles labeled by 1, 2, 3. There are n discs of different sizes on pole 1. Each disc is sitting on a disc with a bigger size. the discs on pole 1 are labeled from 1 to n from top to bottom. Print a sequence of moves such that every move can move only one disc (from one pole to another), no disc may be placed on the smaller disc, one can only move the topmost disc of a pole and put it on the top of any other discs of another pole, and after the sequence of moves, all discs will be on pole 3. An execution of a program to solve the problem is as follows: Input the number discs on the pole a: 2 Move disc 1 from pole 1 to pole 2. Move disc 2 from pole 1 to pole 3. Move disc 1 from pole 2 to pole 3. Consider the following pseudocode function Function name: move Discs input a, b, c: the three poles n. the number of discs on pole a. output none. side effect: print a sequence of moves such that all n discs on a will be moved to pole c using pole b. when needed, as a temporal pole. Plan II fill the plan to write the plan for the function move Discs above, is the following problem decomposition a correct one? Why? P1: move the first (topmost) disc on the pole a to pole b. P2: move the rest of the discs on the pole a to pole c, P3: move the only disc on pole b to pole c.

Explanation / Answer

The given decomposition is partially correct.There should be a modification in it.

P1: Move the first top most disc from pole a to pole b.

P2.: Move the subsequest disc from pole a to c.

P3: When moving the next n-1 disc we should keep the rules in our mind and make the change accordingly by swapping pole b,pole c,pole a one at a time.

For Example.

Let there are four disc in pole A named as w,x,y,z(arraged in descending order,that is z is last then y,then x,then w)

Your steps will be

w to pole b

x to pole c

w to pole c

y to pole b

w to pole a

x to pole b

w to pole b

z to pole c

w to pole c

x to pole a

w to pole a

y to pole c

w to pole b

x to pole c

w to pole c

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote