Skip to content
Official PYQ · 2012

GATE CS 2012 Q16 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

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

Choose one option
View worked solution

Answer: D

To solve the Towers of Hanoi problem with nn discs from a source peg to a destination peg using an auxiliary peg, we follow these optimal steps:

  1. Step 1: Move the top n−1n-1 discs from the source peg to the auxiliary peg. This requires T(n−1)T(n-1) moves.
  2. Step 2: Move the largest (nn-th) disc directly from the source peg to the destination peg. This requires exactly 11 move.
  3. Step 3: Move the n−1n-1 discs from the auxiliary peg to the destination peg. This requires another T(n−1)T(n-1) moves.

Summing the moves for these steps, the total number of moves T(n)T(n) is given by:

T(n)=T(n−1)+1+T(n−1)T(n) = T(n-1) + 1 + T(n-1) T(n)=2T(n−1)+1T(n) = 2T(n-1) + 1

With the base case T(1)=1T(1) = 1 (or T(0)=0T(0) = 0).

Therefore, the correct recurrence relation is T(n)=2T(n−1)+1T(n) = 2T(n-1) + 1, which corresponds to Option D.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions