Menu

[solved]-Want Pseudocode Problem Recursive Step C Code Explained Detail Towers Hanoi Every Building Q38995024

I want the pseudocode for this problem, then the recursive stepof C code explained in detail.

(Towers of Hanoi) Every building computer scientist must grapplewith certain classic problems, and the Towers of Hanoi is one ofthe most famous of these. Legend has it that in a temple in the FarEast, priests are attempting to move a stack of disks from one pegto another. The initial stack had 64 disks threaded onto one pegand arranged from bottom to top by decreasing size. The priests areattempting to move the stack from this peg to a second peg underthe constraints that exactly one disk moved at a time, and at notime may a larger disk be placed above a smaller disk. A third pegis available for temporarily holding the disks. Supposedly theworld will end when the priests complete their tasks, so there’slittle incentive for us to facilitate their efforts. Let’s assumethat the priests are attempting to move the disks from peg 1 to peg3. We wish to develop an algorithm that will print the precisesequence of disk-to-disk peg transfers. If we approach this problemwith conventional methods, we’d ra[od;y find ourselves hopelesslyknotted up in managing the disks. Instead if we attack the problemwith recursion in mind, it immediately becomes tractable. Moving ndisks can be viewed in terms of moving only n-1 disks (and hencethe recursion) as follos:

A) move n-1 disks from peg 1 to peg 2, using peg 3 as atemporary holding area.

b) Move the last disk (the largest) from peg 1 to peg 3.

C) Move n-1 disks from peg 2 to peg 3, using peg 1 as atemporary holding area

The process ends when the last task involves moving n=1 disk,i.e., the base case. This is accomplished by trivially moving thedisk without the need for temporary holding area. Write a programto solve the Towers of Hanoi problem. Use a recursive function withfour pararameters:

a) The number of disks to be moved.

b) The peg on which these disks are initially threaded

c) the peg to which this stack of disks is to be moved

d) The peg to be used as a temporary holding area.

Expert Answer


Answer to I want the pseudocode for this problem, then the recursive step of C code explained in detail. (Towers of Hanoi) Every b… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *