Repository where I mostly put random python scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

12 lines
311 B

def binary_search(arr,element):
lower = 0
upper = len(arr) - 1
while(lower < upper):
mid = (lower + (upper - 1)) // 2
if arr[mid] > element:
upper = mid-1
elif arr[mid] < element:
lower = mid + 1
else:
return True
return False