Top-Down DP with Memoization
Reuse the stored result when the recursion reaches a subproblem it has already solved.
Core Intuition & How It Works
Top-down dynamic programming (memoization) caches the results of recursive subproblems keyed by their state parameters. Repeated states return in O(1), turning exponential recursion trees into polynomial-time algorithms.
In the Byte Sized Algorithms interactive classroom, you can step forward and backward through this algorithm with your keyboard while watching the visual diagram, memory state, and highlighted pseudocode update together.
Time & Space Complexity
| Metric | Complexity |
|---|---|
| Time Complexity | O(states × transition) |
| Space Complexity | O(states + recursion depth) |
| Topic Chapter | Chapter 13: Dynamic Programming |
| Difficulty Level | Advanced |
Key Pattern to Recognize
Identify the minimal state tuple that uniquely determines a subproblem’s answer, then check the memo table before computing.
Common Pitfalls & Edge Cases
Including unnecessary mutable state in the recursion or forgetting to distinguish "cached value 0" from "not yet computed".
Real-World & Technical Interview Applications
Fibonacci, tree DP, game-theory minimax caching, and problems where only a sparse subset of states is reachable.