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

Quiz: Comprehensions and Lambda · Question 15 of 15

Why does the plain recursive Fibonacci become very slow for large n, and what fixes it?

Why does the plain recursive Fibonacci become very slow for large n, and what fixes it?

  1. A.Python limits recursion to 10 calls; use a while loop
  2. B.It recalculates the same values again and again; memoisation (for example lru_cache) stores them
  3. C.Integers overflow; use float
  4. D.It uses too many print statements; remove them
Answer & explanation

Correct answer: It recalculates the same values again and again; memoisation (for example lru_cache) stores them

fib(n) calls fib(n-1) and fib(n-2), which repeat the same work. Caching each result makes it fast.

Can you get the rest right without peeking?

Take the timed Quiz: Comprehensions and Lambda quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →