Skip to content

Instantly share code, notes, and snippets.

@NicolaM94
Created March 9, 2023 17:16
Show Gist options
  • Save NicolaM94/6ae1707c1ff234e2dc93ae47988ac7da to your computer and use it in GitHub Desktop.
Save NicolaM94/6ae1707c1ff234e2dc93ae47988ac7da to your computer and use it in GitHub Desktop.
Binary search implementation
def binarySearch (array, element):
a = 1
b = len(array)
while array[int((a+b)/2)] != element:
m = int((a+b)/2)
if (array[m]) > element:
b = m - 1
else:
a = m + 1
if a > b:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment