Created
June 25, 2017 05:39
-
-
Save LennyBoyatzis/0c62320db35f7289b13ec8b4ec6d5770 to your computer and use it in GitHub Desktop.
Binary Search - Recursive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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