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.
Articles by others on the same topic
There are currently no matching articles.