Dynamic Programming21 sections · 916 units
Open in Course

The Key Observation

Lines in a plane

Plot all lines y=mjx+cjy = m_j x + c_j in the xyxy-plane. For a query point xix_i, you want the line giving minimum yy. Different lines win at different xx values.

A steep negative slope wins for small xx. A gentle slope wins for large xx. At any xx, exactly one line (or a tie) gives the minimum. The set of points where each line is optimal forms the lower envelope. Only lines on this envelope ever contribute to answers. Lines strictly above it are useless.