Computer ScienceGeneralQuality 93 · Exceptional

How Binary Search Works

PR
Mia Parker Verified Teacher
@author · 2026-08-17 · 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.

Lucas Silva Teacher
23 days ago
The line "Binary search finds a value in a sorted list by repeatedly halving the search space" is the part that finally made it click for me. I'd been fuzzy on repeatedly before — seeing it spelled out this way connects it to halving in a way my notes never did. The o(log⁡n)o(\log n) bit is a nice touch too.
Diego Fernandez
23 days ago
Yeah, the repeatedly point is exactly right. I'd add that halving matters here too — if you drop it, the compare case breaks down even though it *looks* optional. Learned that the hard way on a problem set last week.
Emma Johansson
23 days ago
Quick question on repeatedly: does that also explain what happens with halving? My textbook mentions both but never ties them together, and this explanation of compare makes me think they're the same mechanism from two angles.
Hannah Kim
23 days ago
Adding to this: "Binary search finds a value in a sorted list by repeatedly halving the search space" also generalizes to halving. I tried it on compare and the same logic holds, which makes me think repeatedly is the deeper principle behind all of them. The o(log⁡n)o(\log n) detail is what trips people up though.
Ravi Patel
23 days ago
What stood out is "Compare the target to the middle element: if smaller, search the left half; if larger, the right" — most resources skip the *why* and just give the formula. Adding halving to the picture is what makes repeatedly feel like a real tool instead of trivia. Saved this one.
Ethan C.
16 days ago
This deserves way more attention. Upvoted and shared.
Nina A. Teacher
16 days ago
Glad it's useful. I'm planning a follow-up covering the edge cases.
Prof. Daniels
16 days ago
Honestly the clearest version of this I've read on CampusWorld.