Technique
Ternary Search (unimodal optimisation)
Minimise or maximise a unimodal function by discarding a third of the range per step (or binary search on f(m+1) - f(m) for integers).
Learn firstBinary Search
0%
mastery
0/6 solved
0/6 solved
Recognise it
The signal
cost is convex in a single parameter
1Brute force
Evaluate every candidate.
2The observation
Linear scan of the parameter: unimodality means comparing two probes discards a side.
3Why it works
The optimum always lies within [lo, hi].
Reach for it when
- +meeting point that minimises max/sum distance
- +real-valued optimum
Not when
- ×function has plateaus (strict unimodality violated)
- ×multiple local optima
Practice
0/6 solved
- Meeting on the LineCodeforces1600
- Ruler (hard version)Codeforces1700
- Find in Mountain ArrayHard
- Restorer DistanceCodeforces2100
- Minimizing DifferenceCodeforces2000
- Gift SetCodeforces2100
Pitfalls
Misconceptions
- !using ternary search when the predicate is monotone (plain binary search is enough)