Why it matters

Ternary search finds extrema efficiently. Understanding shapes optimization.

Advertisement

The architecture

For unimodal f: try m1 = l + (r-l)/3, m2 = r - (r-l)/3.

If f(m1) < f(m2), max is in [m1, r].

Ternary searchTwo mid pointsm1, m2Compareeliminate 1/3Iteratelog₃ n roundsRequires unimodal — increasing then decreasing (or reverse)
Ternary search steps.
Advertisement

How it works end to end

Discrete: for integer domains, iterate until range = 3.

Continuous: iterate until desired precision.

Requires unimodal function.