ProgrammingHardGATE CS · Campus placements
How many disk moves does the optimal Tower of Hanoi solution need for 5 disks?
- A. 15
- B. 31
- C. 32
- D. 25
Correct answer: B. 31
The recurrence M(n) = 2 M(n-1) + 1 with M(0) = 0 gives 2^n - 1, so M(5) = 31. Each extra disk doubles the work and adds one move.
More C Programming questions
- How many binary strings of length 4 contain at least two adjacent 1s?
- How many subsets of {1, 2, ..., 10} have an even sum of elements? The empty set counts.
- The pairs (1,2), (3,5) and (2,5) are sorted by the second value descending, with ties broken by the first value ascending. Which pair…
- How many integers from 0 to 255 have exactly four 1 bits in binary?
- What is 0 ^ 1 ^ 2 ^ ... ^ 31, the XOR of all integers from 0 to 31?
- What is the total number of 1 bits in the binary forms of 1, 2, ..., 16 added together?