ProgrammingVery hardGATE CS · Campus placements

A recursive Tower of Hanoi solution moves n disks, one at a time, with the rule that a larger disk never sits on a smaller one. How many moves does the recursion make for n = 10?

  1. A. 1000
  2. B. 1023
  3. C. 1024
  4. D. 512

Correct answer: B. 1023

The recurrence is M(n) = 2M(n-1) + 1 with M(0) = 0, which gives 2^n - 1. For n = 10 that is 1023. A common slip is to forget the single move of the largest disk.

More C Programming questions

Exams that ask this topic