Space Optimization
If state `dp[i]` only relies on `dp[i-1]`, we can drop the `i` dimension entirely. This reduces memory usage drastically (e.g. O(N^2) to O(N)).
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
An overview of advanced techniques to reduce time and space complexities in dynamic programming.
If state `dp[i]` only relies on `dp[i-1]`, we can drop the `i` dimension entirely. This reduces memory usage drastically (e.g. O(N^2) to O(N)).
Divide and Conquer and Knuth Optimization rely on the fact that the optimal choice `k` for state `(i, j)` is bounded by choices for adjacent states.
The Convex Hull trick treats DP transitions as linear equations `y = mx + c` and queries the minimum `y` across an envelope of intersecting lines.
Matrix Exponentiation can solve linear recurrence relations (like Fibonacci) in O(log N) time instead of O(N).