🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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))
  1. A.1024
  2. B.1023
  3. C.512
  4. 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 →