Computer ScienceGeneralQuality 69 · Exceptional

How Binary Search Works

PR
Petra Mansoor Verified Teacher
@author · 2026-06-11 · v1
7 min read
Binary search finds a value in a sorted list by repeatedly halving the search space. Compare the target to the middle element: if smaller, search the left half; if larger, the right. This gives
O(log⁡n)O(\log n)
time instead of
O(n)O(n)
for linear search — finding an item in a million entries takes about 20 steps.
0 teacher endorsements

Discussion

Comments support LaTeX — write ∫01x2 dx\int_0^1 x^2\,dx inline with $...$.

Sign in to join the discussion.

No comments yet

Be the first to share your thoughts.