← Quiz: Recurrence Relations: all 10 questions
Quiz: Recurrence Relations · Question 8 of 10
What does this print? (code)
What does this print?
def hanoi(n):
return 1 if n == 1 else 2 * hanoi(n - 1) + 1
print(hanoi(10))
- A.1024
- B.1023
- C.512
- D.2047
Answer & explanation
Correct answer: 1023
Hₙ = 2ⁿ − 1, so H₁₀ = 1023.
Can you get the rest right without peeking?
Take the timed Quiz: Recurrence Relations quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →