You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Binary Search": "Binary Search is a search algorithm that finds the position of a target value within a sorted array. It works by comparing the target value to the middle element of the array; if they are unequal, the lower or upper half of the array is eliminated depending on the result and the search is repeated in the remaining subarray until it is successful.",
3
+
"Applications": [
4
+
"Finding values in a sorted collection",
5
+
"Traversing binary search trees"
6
+
],
7
+
"Complexity": {
8
+
"time": "worst O(log(N)), best O(1), average O(log(N))",
functionBinarySearch(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
+
7
+
varmiddleIndex=Math.floor((minIndex+maxIndex)/2);
8
+
vartestElement=array[middleIndex];
9
+
10
+
tracer._print('Searching at index: '+middleIndex);
0 commit comments