Skip to content

Instantly share code, notes, and snippets.

@sabuhish
Created April 13, 2020 18:46
Show Gist options
  • Select an option

  • Save sabuhish/d74a915c78ddfa99c1c0dd6bbc8a5d2a to your computer and use it in GitHub Desktop.

Select an option

Save sabuhish/d74a915c78ddfa99c1c0dd6bbc8a5d2a to your computer and use it in GitHub Desktop.
arr = [3,4,6,7,14,52]
def binary_search(arr,reqem):
left =0
right = len(arr) -1
while left<=right:
m = (left+right)//2
if arr[m] ==reqem:
return m
elif arr[m]<reqem:
left = m+1
else:
right = m-1
return -1
print(binary_search(arr,52))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment