import math
def BinarySearch( A , val , low , high ):
if high < low :
return -1 #not found
mid = low + (high - low ) /2
if A[mid] > val:
return BinarySearch(A,val , low , high )
if A[mid] < val :
return BinarySearch(A,val,low,high)
else:
return mid #found
A = [ 12 , 23 , 2 , 33 , 123 , 4 , 5 , 2 , 54 , 555 , 21 ]
BinarySearch( A , 0 , 0, 10)
I tried to do Binary Search without using the bisect Module . But it gives an error such as this
File "doubtrob.py", line 8, in BinarySearch
return BinarySearch(A,val , low , high )
RuntimeError: maximum recursion depth exceeded