Skip to content

Commit d2d5efd

Browse files
allentiakrealDuYuanChaoyanglbme
authored
BinarySearch: clearer median computation (TheAlgorithms#2182)
* BinarySearch: clearer median computation ">>> 1" is simply too obscure... * update binary search Co-authored-by: Yang Libin <contact@yanglibin.info> Co-authored-by: Du Yuanchao <shellhub.me@gmail.com> Co-authored-by: Yang Libin <contact@yanglibin.info>
1 parent 02fab66 commit d2d5efd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Searches/BinarySearch.java

Lines changed: 1 addition & 1 deletion
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 - left) >>> 1);
48+
int median = (left + right) >>> 1;
4949
int comp = key.compareTo(array[median]);
5050

5151
if (comp == 0) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy