1
$\begingroup$

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 
  • 2
    @Moron: I've just realized that if you ever decide to change your username, these comments are going to make me look like a real jerk `:)`2010-10-07

1 Answers 1

1

No longer relevant, keeping answer around for comments.

  • 0
    @Moron: Your assumption about my choice of forum is incorrect. I have a clunky recursive solution that works fine, especially since it is done outside of the runtime. I posted here because working on the problem made me curious about a strictly mathematical solution.2010-10-07