Formula to find median in Binary Search changed (#2181)
* Formula to find median in BS changed * Fixed bugs * fixed binary search bug Co-authored-by: Sourav <kalitasourav12@gmail.com.com> Co-authored-by: Du Yuanchao <shellhub.me@gmail.com>
This commit is contained in:
parent
cebd052c94
commit
b8707e61cb
@ -45,7 +45,7 @@ class BinarySearch implements SearchAlgorithm {
|
||||
if (right < left) return -1; // this means that the key not found
|
||||
|
||||
// find median
|
||||
int median = (left + right) >>> 1;
|
||||
int median = left + ((right-left) >>> 1);
|
||||
int comp = key.compareTo(array[median]);
|
||||
|
||||
if (comp == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user