Finding the closest value to n without going into a sorted array

For this task, I have a sorted array of doubles. I need to be able to quickly and efficiently find the index of the closest value, but no more, n. Efficiency is key, assignment states can be executed in O (log n), so I assume that this can be done using some kind of modified binary search.

I know this was asked before, but all the answers that I found were either assuming an unsorted array, or just looped around the whole array, comparing the differences.

Any guidance is appreciated. Thank.

0
source share
1 answer

, ;

  • , (, )
  • , , , ( , ).
  • , , , , , , .

, , , :)

+2

All Articles