Skip to content

Instantly share code, notes, and snippets.

@FeeYo7
Created November 5, 2021 14:39
Show Gist options
  • Save FeeYo7/c05723b6289a26e913008c1dd5ed9e42 to your computer and use it in GitHub Desktop.
Save FeeYo7/c05723b6289a26e913008c1dd5ed9e42 to your computer and use it in GitHub Desktop.
simple recursive binary search implementation
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)
@FeeYo7
Copy link
Author

FeeYo7 commented Nov 5, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment