🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Recursion and Stack Frames: all 10 questions

Quiz: Recursion and Stack Frames · Question 5 of 10

Why is the naive recursive Fibonacci slow?

Why is the naive recursive Fibonacci slow?

  1. A.Recursion is always slower than loops by a factor of n
  2. B.The same subproblems (like fib(2)) are computed again and again, giving an exponential number of calls
  3. C.It uses floating-point numbers
  4. D.The base case is wrong
Answer & explanation

Correct answer: The same subproblems (like fib(2)) are computed again and again, giving an exponential number of calls

fib(25) needs 242,785 calls; a loop or memoisation needs about 25 steps.

Can you get the rest right without peeking?

Take the timed Quiz: Recursion and Stack Frames quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →