Overview
In standard Interval DP, we test `k` from `i` to `j`, taking O(N) time per state, leading to O(N³). Knuth Optimization limits `k` to a tiny range.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
An advanced technique to optimize certain O(N³) Interval DP problems down to O(N²) by bounding the search space of the split point k.
In standard Interval DP, we test `k` from `i` to `j`, taking O(N) time per state, leading to O(N³). Knuth Optimization limits `k` to a tiny range.
Knuth applies when the cost function satisfies the Quadrangle Inequality and monotonicity on the lattice of intervals.
Instead of i ≤ k < j, we use opt[i][j-1] ≤ k ≤ opt[i+1][j]. The optimal split for [i, j] is bounded by the optimal splits of its slightly smaller sub-intervals.
Because the upper bound of one interval is the lower bound of the next, the work done in the inner loop telescopes, amortizing the total time to exactly O(N²).