|
|
|
|
|
by eesmith
1326 days ago
|
|
Yes, if you want a solution to a related problem then the implementation will need a better midpoint calculation. However, the linked-to binary search starts from 0: 1: public static int binarySearch(int[] a, int key) {
2: int low = 0;
3: int high = a.length - 1;
and the promoted fix is: 6: int mid = low + ((high - low) / 2);
The aforementioned Wikipedia binary sort also takes a length, rather than start/end: function binary_search(A, n, T) is
L := 0
R := n − 1
|
|
https://en.cppreference.com/w/cpp/algorithm/lower_bound