March 24
Binary Search
What binary search means, when halving the search space makes sense, and why sorting is not the only useful signal.
What it is
Binary search means searching by eliminating half of the space at each step.
Instead of moving one item at a time, you use the middle to decide whether the answer is on the left or the right.
When to use it
The obvious case is sorted data.
But the pattern also appears when there is a monotonic condition such as:
- false up to this point
- true from here onward
Common mistake
The classic mistake is memorizing “it only works on sorted arrays” and stopping there.
In practice, it also helps you find the first point where a condition becomes true.
Better question
Before applying it, ask:
- can I safely discard half the search space?
- is there real order or monotonicity here?
- am I searching for an exact value or for a boundary?
Share this page
Copy the link manually from the field below.