Dynamic Programming: Top-Down
Take a recursion that repeats itself exponentially and make it polynomial by writing each answer down the first time you compute it.
After this lesson you will be able to
- Recognise overlapping subproblems in a recursion tree and explain why they make naive recursion exponential.
- Turn a recursive solution into a memoized one using a dictionary or
functools.lru_cache. - Define a DP state, a transition and base cases for a new problem.
- Compute the time of a DP as (number of states) × (work per state).
- Solve minimum-coins and longest-common-subsequence with top-down DP.
Before you start. Recursion I is essential: you should be comfortable tracing a recursive function and its base case.