The Runtime Theory

Binary Search Keeps a Valid Answer Inside the Range

Step through the invariant and branch decisions that shrink a sorted search range to one answer.

The Runtime Theory Team05 stages

trace / request.md

CANDIDATE RANGECHOOSE MIDPOINTCOMPARESHRINK INTERVALRETURN BOUNDARY

readyStart with the half-open interval [lo, hi). The target's lower-bound position must remain inside it.

The flow describes a lower-bound search, which returns the first index whose value is at least the target. The invariant, rather than the midpoint formula alone, is the proof that the result is correct.

Not started

Sign in to save your learning progress.

Sign in to save