Skip to content

Instantly share code, notes, and snippets.

@dariodip
Last active March 20, 2021 13:32
Show Gist options
  • Save dariodip/f8110d1262241e3fed64f17e67ec8f76 to your computer and use it in GitHub Desktop.
Save dariodip/f8110d1262241e3fed64f17e67ec8f76 to your computer and use it in GitHub Desktop.
from math import floor
def bsa(a, n, t):
lft = 0
rgt = n -1
while lft <= rgt:
m = floor((lft + rgt) / 2)
if a[m] < t:
lft = m+1
elif a[m] > t:
rgt = m-1
else:
return m
return -1
@dariodip
Copy link
Author

fix name of variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment