Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M7274

Binary Search Logic

Binary Search Logic
StructuremediumLogic
Included
account_tree

Updated 2026-08-10

Loading revision record…

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.

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/2

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

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.

  • link
    en.wikipedia.orghttps://en.wikipedia.org/wiki/Binary_searchZH · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS