Computer ScienceGeneralQuality 89 · Exceptional

Binary search: the invariant that makes it work

PR
Victoria AlexanderTeacher Tier
@author · 2026-08-14 · v1
7 min read
At every step, the target—if present—remains inside the current search interval. Comparing the midpoint lets us discard half the interval without breaking that invariant. The logarithmic running time comes from repeatedly halving the remaining candidates, not from the syntax of the loop.
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.