Skip to content

Commit 60893cd

Browse files
committed
added base case for recursive binary search algorithm
1 parent a8f9061 commit 60893cd

File tree

1 file changed

+5
-0
lines changed
  • algorithm/search/binary_search/recursive

1 file changed

+5
-0
lines changed

algorithm/search/binary_search/recursive/code.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
function BinarySearch(array, element, minIndex, maxIndex) { // array = sorted array, element = element to be found, minIndex = minIndex index, maxIndex = maxIndex index
2+
if (minIndex > maxIndex) {
3+
tracer._print(element + ' is not found!');
4+
return -1;
5+
}
6+
27
var middleIndex = Math.floor((minIndex + maxIndex) / 2);
38
var testElement = array[middleIndex];
49

0 commit comments

Comments
 (0)