Skip to content

Instantly share code, notes, and snippets.

@astro313
Created October 21, 2017 15:59
Show Gist options
  • Select an option

  • Save astro313/fb91eb9c5866936abf31ef8ca7eecd84 to your computer and use it in GitHub Desktop.

Select an option

Save astro313/fb91eb9c5866936abf31ef8ca7eecd84 to your computer and use it in GitHub Desktop.
Binary search function
import math
def binary_search(array, search):
m = 0
i = 0
z = len(array) - 1
while i<= z:
m = math.floor(i + ((z - i) / 2))
if array[m] == search:
return m
elif array[m] < search:
i = m + 1
elif array[m] > search:
z = m - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment