Binary Search Logic
Updated 2026-08-10
Summary
In a sorted sequence, compare the middle and throw half away each time: a thousand items take only ten probes.
Definition
In an ordered sequence, compare the midpoint against the target and discard half of the range each time, which locates the target in logarithmic time. As a scaffold it is exponential speedup: a thousand options can be settled with only ten comparisons, provided that the sequence has been sorted beforehand.
Introduction
How to use
- Sort first: confirm the set really is ordered, or the whole method fails. - Middle probe: compare the midpoint against the criterion you are hunting for. - Half cut: go left when it is less, and go right when it is more.
Mechanism
In an ordered set you compare at the midpoint and halve the candidate range each step, so n items take at most log base two of n comparisons, an O of log n cost. The crux is the sorted precondition, which is what makes discarding half a safe move rather than a gamble.
Practice
In progress 0/2Practice this model in one real situation:
Cases
- Finding a single value in a sorted array is the textbook use of it.
- Debugging drops a breakpoint at the code's midpoint to halve the suspect span.
- The number-guessing game is just higher-or-lower, halving the range each time.
Common pitfalls
- Running a binary split on data that was never sorted at all to begin with.
- Using a bisection where the task really calls for a full scan, and so missing answers.
Sources
Source support: Explicit
References currently contain only Wikipedia links; primary sources still need review.
- en.wikipedia.orghttps://en.wikipedia.org/wiki/Binary_searchverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS