Overview
Binary Search compares the target with the middle item of a sorted range. Each comparison discards the half of the range that cannot contain the answer.
Finds a target or insertion point in sorted data by repeatedly halving the candidate range.
Compact metadata for implementation and discovery.
Binary Search compares the target with the middle item of a sorted range. Each comparison discards the half of the range that cannot contain the answer.
Quick facts
Runtime and memory behavior at a glance.
Best
O(1)
Average
O(log n)
Worst
O(log n)
Space
O(1)
mid = low + floor((high - low) / 2)Chooses the middle of the active search interval while avoiding overflow in some languages.
Show the active search range shrinking after each comparison.
Binary search also applies to monotone answer spaces, not only explicit sorted arrays.
What each reference supports for this entry.
Algorithms textbook support for Binary Search's invariant, correctness argument, and asymptotic analysis.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Searching · Core
Binary search on answer applies binary search to a monotone predicate over answer values.
Compare with thisSearching · Core
Interpolation search probes a sorted range like binary search but estimates the split from key values.
Compare with thisSearching · Core
Uniform binary search is a table-driven variant of binary search with precomputed probe offsets.
Compare with thisSearching · Foundation
Binary search is faster on sorted data but requires order.
Compare with thisBinary search is faster on sorted data but requires order.
Lower bound adapts binary search to find the first valid insertion position.