Computer Science / Algorithms
Part of the Binary Search Learning Experience →Watch low, high, and mid pointers narrow in on a target — or prove it's absent — by halving a sorted array each step.
Binary search only works on sorted data. Each step compares the target to the value at the midpoint of the current low–high range: an exact match ends the search, a smaller midpoint value moves the search into the right half, and a larger one moves it into the left half. Because the range halves every step, the search finishes in about log₂(n) comparisons — even when the target isn't in the array at all, which this visualizer also demonstrates. Press Reset to generate a new random sorted array and target and see the process repeat on a different case.
Binary search eliminates half the remaining range on every comparison by assuming everything below mid is smaller and everything above is larger. On unsorted data that assumption doesn't hold, so the eliminated half could still contain the target.
The low and high pointers keep narrowing until high drops below low — an empty range. That's proof the target doesn't exist, not just a failed guess. This visualizer generates that case on some runs so you can see it happen.
Each comparison discards half of whatever range remains, so the range shrinks n → n/2 → n/4 → … until one element is left. The number of halvings needed is log₂(n), which is why the Range size counter roughly halves every step.