Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This homework is based on C Program only till chapter Arrays. HELP NEEDED ASAP! 3. Consider the magic tower problem again. Magic tower problem: there
This homework is based on C Program only till chapter Arrays.
HELP NEEDED ASAP!
3. Consider the magic tower problem again. Magic tower problem: there are three poles labeled by I, 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 a. b. c. every move can move only one disc (from one pole to another) no disc may be placed on a smaller disc, one can only move the top most 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 d. An execution of a program to solve the problem is as follows Input the number discs on 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. a.) Consider the following pseudocode function Function name: moveDiscs 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 I/ fill the plan To write the plan for the function moveDiscs above is the following problem decomposition a correct one? Why? P1: move the first (top most) disc on pole a to pole b, P2: move the rest of the discs on pole a to pole c. P3: move the only disc on pole b to pole c. b.) No loop statement is allowed. Complete the plan for the function moveDises2 below. Note that this function has one less parameter about the poles. It has only two poles as parameters, one parameter less than function moveDiscs above. The purpose of this practice is to help you realize that there may be different ways to design a function to solve a given (sub)problem. [Hint. In your plan, you still need to use the third pole. But you can figure out the third pole from a and b. For example, if a is 2 and b is 3, the third pole is 1. Function name:moveDises2 input a, b: the two poles (b is the pole we would like to move the discs to) n: the number of discs on pole a. output side effect: print a sequence of moves such that all n discs on a will be moved to pole b (following the rules on moves) Data//Your auxiliary data is here, if there is any Plan l fill the planStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started