When we want to calculate the middle element of a segment of array, we should use \((high-low)/2+low\) instead of \((low+high)/2\). Why?

The reason is we may not know the scope of input size of the array. If it is near from the upper bound of the data type used, \(low+high\) may overflow. But \(high-low\) can’t.

Leave a Reply

Your email address will not be published. Required fields are marked *