Overview
Interval DP is used when you can merge adjacent items. The cost of merging a large interval depends on where you split it into two smaller chunks.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A structural pattern for solving problems where the solution for an interval [i, j] depends on breaking it down into smaller sub-intervals.
Interval DP is used when you can merge adjacent items. The cost of merging a large interval depends on where you split it into two smaller chunks.
Unlike linear DP, we don't iterate `i` from 0 to N. We iterate over the LENGTH of the interval, from 2 to N, because larger intervals depend on smaller ones.
For a fixed interval `[i, j]`, we test every possible split point `k`. We combine the optimal answer for `[i, k]` and `[k+1, j]`.
Classic problems include Matrix Chain Multiplication, Burst Balloons, Minimum Cost to Merge Stones, and Optimal Binary Search Trees.
| [0,0] | [0,1] | [0,2] | [0,3] |
| [1,1] | [1,2] | [1,3] | |
| [2,2] | [2,3] | ||
| [3,3] |