For this problem I have a sorted Array of doubles. I need to be able to quickly and efficiently find index of the value that is closest to, but not over, n. Efficiency is key, the assignment states is can be done in O(log n) so I assume it can be done with some sort of modified binary search.
I know this has been asked before but all answers I found either assumed an unsorted array or simply looped through the entire array comparing differences.
Any guidance is appreciated. Thank you.
Yes, you can do it with a modified binary search; just look for the number as usual and;
Just remember that there are some error conditions to consider too and you’ll do fine 🙂