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
defbinarySearch (arr, l, r, x):
# Check base case ifr>=l:
mid=l+ (r-l)/2# If element is present at the middle itself ifarr[mid] ==x:
returnmid# If element is smaller than mid, then it # can only be present in left subarray elifarr[mid] >x:
returnbinarySearch(arr, l, mid-1, x)
# Else the element can only be present # in right subarray else:
returnbinarySearch(arr, mid+1, r, x)
else:
# Element is not present in the array return-1