Dynamic Programming21 sections · 916 units
Open in Course

What Is Knuth's Optimization?

Core idea

Interval DP has form: dp[i][j]=minikj(dp[i][k1]+dp[k+1][j])+cost(i,j)dp[i][j] = \min_{i \leq k \leq j}(dp[i][k-1] + dp[k+1][j]) + cost(i,j). Some variants use k<jk < j depending on the problem.

Naive: O(n2)O(n^2) states, O(n)O(n) choices per state = O(n3)O(n^3). Knuth's observation: if cost satisfies QI, then opt[i][j1]opt[i][j]opt[i+1][j]opt[i][j-1] \leq opt[i][j] \leq opt[i+1][j]. This double bound limits where to search for kk. Summed over all states, total work becomes O(n2)O(n^2).