Dynamic Programming21 sections · 916 units
Open in Course

Knuth's Optimization - Walkthrough

Tracing the double bound

Interval DP: dp[i][j]=mink(dp[i][k]+dp[k+1][j])+cost[i][j]dp[i][j] = \min_{k} (dp[i][k] + dp[k+1][j]) + cost[i][j]. With QI, opt[i][j1]opt[i][j]opt[i+1][j]opt[i][j-1] \leq opt[i][j] \leq opt[i+1][j].

For interval [0,4][0, 4]: opt[0][3]opt[0][4]opt[1][4]opt[0][3] \leq opt[0][4] \leq opt[1][4]. The search range for opt[0][4]opt[0][4] is bounded. Fill by diagonal (increasing interval length). For each interval, the bounded search guarantees amortized O(1)O(1) per interval. Total: O(n2)O(n^2) for all intervals, down from O(n3)O(n^3). Critical for n=5000n = 5000 problems.