Dynamic Programming21 sections · 916 units
Open in Course

Intro

What you'll learn

I teach you two optimizations that skip unnecessary work. Both rely on a property called the quadrangle inequality. When it holds, the optimal split point is monotonic: opt[i]opt[i+1]opt[i] \leq opt[i+1] for all ii.

As ii increases, the best split never moves backward, so you can predict where to look. Knuth's improvement turns O(n3)O(n^3) interval DP (dynamic programming) into O(n2)O(n^2). D&C improvement turns O(kn2)O(kn^2) partitioning DP into O(knlogn)O(kn \log n). By the end, you'll understand why these optimizations work, when to apply them, and how to implement them.