Skip to content

Commit b8707e6

Browse files
SouravjyotiSouravrealDuYuanChao
authored
Formula to find median in Binary Search changed (TheAlgorithms#2181)
* Formula to find median in BS changed * Fixed bugs * fixed binary search bug Co-authored-by: Sourav <[email protected]> Co-authored-by: Du Yuanchao <[email protected]>
1 parent cebd052 commit b8707e6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Searches/BinarySearch.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private <T extends Comparable<T>> int search(T array[], T key, int left, int rig
4545
if (right < left) return -1; // this means that the key not found
4646

4747
// find median
48-
int median = (left + right) >>> 1;
48+
int median = left + ((right-left) >>> 1);
4949
int comp = key.compareTo(array[median]);
5050

5151
if (comp == 0) {

0 commit comments

Comments
 (0)