Created
November 5, 2021 14:39
-
-
Save FeeYo7/c05723b6289a26e913008c1dd5ed9e42 to your computer and use it in GitHub Desktop.
simple recursive binary search implementation
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
import math | |
def binarysearch(arr, key, low, high): | |
if low > high: | |
return -1 | |
mid = math.floor((high+low)/2) | |
if arr[mid] == key: | |
return mid | |
if arr[mid] > key: | |
return binarysearch(arr, key, low, mid-1) | |
else: | |
return binarysearch(arr, key, mid+1, high) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bambooozeld