Question

The recurrence relation capturing the optimal execution time of the Towers of Hanoi problem with nn discs is

Choose one option
Official answer and solution
Official answer
D
From
Official GATE 2012 answer key

Solution

Formulate the recurrence relation for moving nn disks between three pegs in the classic Towers of Hanoi puzzle.

  1. To transfer nn disks from the source peg AA to the target peg CC using auxiliary peg BB:
  • Step 1: Recursively move the top n−1n - 1 disks from peg AA to peg BB. This requires T(n−1)T(n - 1) optimal moves.
  • Step 2: Move the single largest disk (nn-th disk) directly from peg AA to peg CC. This takes exactly 1 move.
  • Step 3: Recursively move the n−1n - 1 disks from peg BB to peg CC using peg AA. This requires T(n−1)T(n - 1) optimal moves.
  1. Summing the moves gives the recurrence relation:
T(n)=T(n−1)+1+T(n−1)=2T(n−1)+1T(n) = T(n - 1) + 1 + T(n - 1) = 2T(n - 1) + 1

with base condition T(1)=1T(1) = 1.

  1. Solving this recurrence yields T(n)=2n−1T(n) = 2^n - 1, confirming option (D).
Final answer

D

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2012 Computer Science and Information Technology (CS)
Question
16 of 65, printed as CS Q.16
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.