Computer Science I / Dynamic Programming Intuition
Practice question · Multiple choice

Naive recursive Fibonacci takes exponential time; adding memoisation makes it linear. Why does storing results change the growth class so dramatically?

Hints
  1. Draw the call tree for F(5). How many times does F(2) appear?
  2. Ask how many DISTINCT subproblems exist for F(n).
Show the answer

B. Because the naive version recomputes the same subproblems exponentially.

Why

Draw the call tree and the waste is visible: about 2ⁿ nodes containing only n distinct values. Memoisation removes duplication rather than speeding anything up, so the work becomes proportional to the number of distinct subproblems. That identifies when the technique applies, overlapping subproblems, plus optimal substructure. Merge sort's halves are all distinct, so there is nothing to reuse.

Read the lesson: Dynamic Programming Intuition →

Practise Dynamic Programming Intuition

The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Dynamic Programming Intuition