Is there a simple function which can be used to determine the two "next" search indexes in a binary search?

168 Views Asked by At

Edit: question simplified to remove confusion

Assuming a sorted list of items with indexes from 1 to N, and given only an index number i and the maximum index N, is there a simple function which will return the two possible indexes that would be reached next in a binary search of the list?

Example:

i = 6
N = 8
LeftSearchIndex(i, N) = 5
RightSearchIndex(i, N) = 7
1

There are 1 best solutions below

16
On

No longer relevant, keeping answer around for comments.