matthewsamuel95 / ACM-ICPC-Algorithms

Algorithms used in Competitive Programming
2.1k stars 1.27k forks source link

binsearch-bug #687

Closed Orasz closed 6 years ago

Orasz commented 6 years ago

Corrected the famous binary search bug: when searching for the middle element of an array it is unsafe to do midlle = (high + low) /2 because it can lead to an overflow error, the safe version is middle = (low + (high - low))/2.