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:
Sourav Jyoti Kalita 2021-04-14 09:20:48 +05:30 committed by GitHub
parent cebd052c94
commit b8707e61cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {