arrayscomplexitysearching
A half-open interval keeps binary search tidy
Anonymous
For a sorted array, search the half-open interval from lo inclusive to hi exclusive. While lo is below hi, set mid to the midpoint, rounded down. If the middle value is below target, move lo to mid plus one; otherwise move hi to mid. The loop ends at the first position whose value is at least target, or at the end of the array. Check that the position is not the end before testing for equality. This takes O(log n) time on a sorted random-access array.
0