← Back to the searching page
Ternary Search & Unimodal Optimization
When a function rises then falls (or vice versa), two probe points per step shrink the search interval around the peak.
What to know
- Requires strict unimodality — plateaus break the comparison logic.
- Two midpoints m1, m2 discard the third of the range that cannot hold the optimum.
- On integer domains, binary search on the slope is often simpler.
In the wild: Hyperparameter sweeps, physics trajectory optima, cost-curve minimization.
Algorithms to reach for
Ternary search
O(log n)Maximize/minimize unimodal functions
Peak finding
O(log n)Any local peak via slope binary search (LeetCode 162)
Practice problems — with full guides
Each problem has its own page: progressive hints, how to approach it, and the full solution.