Which of the two is best for implementing binary search?

In an array with a low and a high index of the left and right borders, respectively, there are two ways to find the middle element:

1. int mid = (low+high)/2;
2. int mid = low + ((high - low) / 2);
+4
source share
1 answer

The first implementation will simply cause the variable to overflow. The second will take care of this.

+3
source

All Articles