Created
February 10, 2020 14:24
-
-
Save manojnaidu619/e69ced5746d26f17b86c00ca5a6b3d6d to your computer and use it in GitHub Desktop.
Binary Search in Python(Recursive version)
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 binarySearch(arr, key, low, high): | |
if low>high: | |
return False | |
else: | |
mid = (low+high)/2 | |
if arr[mid]==key: | |
return True | |
elif key<arr[mid]: | |
return binarySearch(arr,key,low,mid-1) | |
else: | |
return binarySearch(arr,key,mid+1,high) | |
result = binarySearch([1,2,3,4,5],6,0,4) | |
if result: print("Element found!") | |
else: print("Element not found!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment