The Core Idea

How binary search halves the search space.

Binary search works on any space with a yes/no question that partitions it.

1.1. Define [low,high][low, high].

2.2. Pick mid=(low+high)/2mid = (low + high) / 2.

3.3. Check condition at midmid.

4.4. Narrow to [low,mid][low, mid] or [mid+1,high][mid+1, high].

5.5. Repeat until one element.

O(logn)O(\log n): Each step halves the space. After kk steps: n/2kn/2^k elements. When n/2k=1n/2^k = 1, k=log2nk = \log_2 n.

Requires monotonic property: condition true on one side, false on the other.