Overview
Binary search on answer converts an optimization problem into repeated yes/no feasibility checks. If feasibility is monotone over the candidate answer range, binary search can find the boundary value.
Finds an optimal numeric answer by binary searching a monotone feasibility predicate.
Compact metadata for implementation and discovery.
Binary search on answer converts an optimization problem into repeated yes/no feasibility checks. If feasibility is monotone over the candidate answer range, binary search can find the boundary value.
Quick facts
Runtime and memory behavior at a glance.
Best
O(log r)
Average
O(T log r)
Worst
O(T log r)
Space
O(1)
if feasible(mid), high = mid else low = mid + 1Uses a monotonic yes/no test to keep the half that can still contain the best answer.
Show a feasible boundary moving through a numeric answer range.
The algorithm is only as valid as the monotonicity of the feasibility predicate.
What each reference supports for this entry.
Algorithms textbook support for Binary Search on Answer invariants, search ordering, correctness argument, or asymptotic analysis.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Binary search on answer applies binary search to a monotone predicate over answer values.
Both solve optimization-style problems through monotone decision checks.