Let us assume that the priests are attempting tomove the disks from peg 1 to peg
ID: 3618056 • Letter: L
Question
Let us assume that the priests are attempting tomove the disks from peg 1 to peg 3. We wish to develop an algorithmthat prints the precise sequence of peg-to-peg disk transfers.
If we were to approach this problem withconventional methods, we would rapidly find ourselves hopelesslyknotted up in managing the disks. Instead, attacking this problemwith recursion in mind allows the steps to be simple. Moving ndisks can be viewed in terms of moving only n1 disks (hence, therecursion), as follows:
Move n 1 disks from peg 1 to peg 2, using peg 3as a temporary holding area.
Move the last disk (the largest) from peg 1 topeg 3.
Move the n 1 disks from peg 2 to peg 3, usingpeg 1 as a temporary holding area.