AlgoViz

Binary search

easy 16 min

Binary search finds a value, a boundary or an insertion point in sorted data by checking the middle and discarding the half that cannot hold the answer.

The binary search toolkit

Read it, run it, change a line and run it again.

Loading editor…

Classic exact match, both bounds on a half-open interval, first and last occurrence built from the bounds, and a generic first-true search on any monotonic predicate.