← 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?
- A.Recursion is always slower than loops by a factor of n
- B.The same subproblems (like fib(2)) are computed again and again, giving an exponential number of calls
- C.It uses floating-point numbers
- 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 →