Summary
Binary search is a fast way to locate an item in a sorted list by repeatedly
checking the middle element and discarding the half that can’t contain the answer.
- Requirement: the data must be sorted (commonly ascending).
- Idea: compare the middle value to the target, then keep only the left or right half.
- Result: returns the matching index (or “not found” if the target isn’t present).
Performance: O(log n) time, O(1) extra space.