Mark As Completed Discussion

Identify the Subproblems

The subproblems are just the recursive calls of fib(n-1) and fib(n-2). We know that fib(n) is the nth Fibonacci number for any value of n so we have our subproblems.

With our subproblems defined, let's memoize the results. This means we're going to save the result of each subproblem as we compute it and then check before computing any value whether or not its already computed. However, this will only require tiny changes to our original solution.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment