Dynamic Programming21 sections · 916 units
Open in Course

Why D&C Is O(n log n)

The analysis

The recursion depth is O(logn)O(\log n) because you halve the state range each time. At each depth, the search ranges [optL,optR][optL, optR] across all calls are nearly disjoint. When you find opt[mid]=kopt[mid] = k, the left child gets range [optL,k][optL, k] and the right child gets [k,optR][k, optR]. These don't overlap except at kk.

So all calls at the same depth search a total of O(n)O(n) values. With O(logn)O(\log n) depths, total work is O(nlogn)O(n \log n). For layered DP with gg layers, you run D&C once per layer: O(gnlogn)O(g \cdot n \log n) total.