Skip to interview prep
Apexed

7. Why is naive recursive Fibonacci slow, and how does memoization fix it?

MediumRecursion & backtracking

Technical

Type or dictate your answer. Your draft is saved on this device.

Show model answer

fib(n) = fib(n−1) + fib(n−2) recomputes the same values exponentially many times: about O(φⁿ) calls. Memoization caches each result the first time, so every fib(k) is computed once and the total is O(n).

Example program

Why is naive recursive Fibonacci slow, and how does memoization fix it — Data structures & algorithms interview question — Apexed