Dynamic Programming21 sections · 915 units
Open in Course

Li Chao Tree - Walkthrough

Understanding the structure

Li Chao tree: segment tree over x-values. Each node stores the line that's best at the midpoint of its range. Insert line LL: compare with current line at midpoint.

The winner stays. The loser might still be optimal in some child. Recurse into the half where the loser could win. At most O(log⁡n)O(\log n) nodes visited per insert. Query x: traverse from root to leaf for x. At each node, evaluate the stored line. Return the minimum across all nodes on the path.