Skip to content

Instantly share code, notes, and snippets.

@nickwhite917
Created February 13, 2017 01:33
Show Gist options
  • Select an option

  • Save nickwhite917/31acafb596fd7fb168fa4a6714ced425 to your computer and use it in GitHub Desktop.

Select an option

Save nickwhite917/31acafb596fd7fb168fa4a6714ced425 to your computer and use it in GitHub Desktop.
Binary Search in Python
def binary_search(ele, arr, min = 0, max = None):
if max is None:
max = len(arr) - 1
half = min + (max - min) / 2
value = arr[half]
if value == ele:
return half
if ele < value:
max = half
return binary_search(ele, arr, min, max)
if ele > value:
min = half
return binary_search(ele, arr, min, max)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment