3 ms·
https://en.wikipedia.org/wiki/Binary_search_algorithm#Implementation_issues https://en.wikipedia.org/wiki/Binary_search_algorithm#Implem... People often do (L+
by OnionBlender 4y ago
https://en.wikipedia.org/wiki/Binary_search_algorithm#Implementation_issues https://en.wikipedia.org/wiki/Binary_search_algorithm#Implem...
People often do (L+R)/2 but that can overflow. Using L+(R-L)/2 avoids the overflow problem.
- nomel 4y agoAs someone who has a binary search in their interview question, I will claim that far more people run into the problem of trying to do midpoint/2 and midpoint*2, long before overflows.