BET ADA_1_intro
Sunday, October 31, 2021 10:44 AM
General Page 1
General Page 2
General Page 3
General Page 4
General Page 5
General Page 6
General Page 7
General Page 8
https://www.lucidchart.com/
BinarySearchAlgorithm(A,x,size){
//A = Sorted array, "x"=element to be searched and "size" = size of array
Low:=0, high:=size-1
while low<=end
mid:=(low+high)/2
If a[mid]= x
return mid
then
Else
If a[mid]<x
low=mid+1
else
endif
high=mid-1
EndWhile
Step 1: Start
Step 2: Input Sorted array in "a[]" and element to be searched in "x" and size of array in "size"
Step 3: Initialize low=0, high=size-1
Step 4: Repeat until start>=end
Step 4.1: mid=(low+high)/2
Step 4.2: If a[mid] is equal to x , then xis found.print index value of mid and exit
Step 4.3: Else check if x is less than a[mid] search left of array by adjusting the array index as high=mid-1
Step 4.5 : else, search right of array by adjusting the array index as low=mid+1
Step 5: Print x not found in the list
Stop 6: Stop
General Page 9
General Page 10
General Page 11
General Page 12

Time and Space complexity of Algorithms