Dynamic Programming21 sections · 916 units
Open in Course

Visualizing Knuth

Mental model

Imagine a 22D (two-dimensional) grid where (i,j)(i, j) is a cell. You fill the grid diagonal by diagonal (by length). For cell (i,j)(i, j), you look at (i,j1)(i, j-1) (one left) and (i+1,j)(i+1, j) (one down).

Their optopt values bound where to search. The search range for each cell is small. Across a diagonal, ranges tile the space without much overlap. That's why the total is O(n)O(n) per diagonal, O(n2)O(n^2) overall.