Lower-bound binary search invariant
ID: lower-bound-binary-search-invariant
In a nondecreasing array, the first position whose entry is at least is found by maintaining a half-open unresolved interval . Entries before are smaller than ; entries from onward are at least . Initially . At midpoint , replace by if , and otherwise replace by . Monotonicity preserves the loop invariant, and decreases. On exit is the first qualifying position, or if no such entry exists. Repeated values and endpoint cuts require no additional case.
New to topics? Read the docs here!