| 4* |
Consider the following extension of the Towers of Hanoi problem,
in which there are four pegs A, B, C, and D,
and n squares of varying sizes.
Initially the squares are stacked on peg A in order of decreasing
size, the largest square on the bottom.
The problem is to move the squares from peg A to peg B
one at a time in such a way that no square is ever placed
on a smaller square.
Pegs C and D may be used for temporary storage of squares.
Write an efficient recursive algorithm to solve this problem.
What is the execution time of your algorithm in terms of
the number of times a square is moved?
|
recursion |