Skip to content

Instantly share code, notes, and snippets.

@LennyBoyatzis
Created June 25, 2017 05:39
Show Gist options
  • Save LennyBoyatzis/0c62320db35f7289b13ec8b4ec6d5770 to your computer and use it in GitHub Desktop.
Save LennyBoyatzis/0c62320db35f7289b13ec8b4ec6d5770 to your computer and use it in GitHub Desktop.
Binary Search - Recursive
def binary_search_recursion(sorted_list, key, low, high):
if low > high:
return -1
mid = int(low + ((high - low)/2))
if sorted_list[mid] == key:
return mid
elif (key < sorted_list[mid]):
return binary_search_recursion(sorted_list, key, low, mid - 1)
elif (key > sorted_list[mid]):
return binary_search_recursion(sorted_list, key, mid + 1, high)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment