Question: The following code segment simulates moving n disks on the peg start to peg end through peg temp . Only one disk can be moved
The following code segment simulates moving n disks on the peg start to peg end through peg temp. Only one disk can be moved at a time. What is the time complexity (Big O) ?
moveTower( n, start, end, temp)
{
if (n ==1 )
moveOneDisk(start, end);
else
{
moveTower( n-1, start, temp, end);
moveOneDisk(start, end);
moveTower( n-1, temp, end, start);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
