Skip to content

Instantly share code, notes, and snippets.

@shakeelmajeed-work
Created July 23, 2020 20:32
Show Gist options
  • Save shakeelmajeed-work/2247d5e857bb7f4e98329e70b643df27 to your computer and use it in GitHub Desktop.
Save shakeelmajeed-work/2247d5e857bb7f4e98329e70b643df27 to your computer and use it in GitHub Desktop.
Binary Search in Python 3!
def dosearch(array, target):
min = 0
max = len(array) - 1
array = sorted(array)
while min<=max:
guess = (min+max) // 2
if array[guess] == target:
return guess
elif array[guess] < target:
min = guess + 1
else:
max = guess - 1
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment