Math Fundamentals18 sections · 814 units
Open in Course

Binary Search - Insight

(Divide and conquer)

Each comparison eliminates half the array. After 1 step, n/2 remain. After 2 steps, n/4 remain. After k steps, n/2^k remain.

When n/2^k = 1, you have found the target or determined it does not exist. Solving gives k = log₂(n).

This is O(log n). No other comparison-based search can beat this on sorted data.