Binary Search in Python
def binary_search(lst,search):
lst.sort()
print(lst)
lb = 0
ub = len(lst)-1
res = False
while(lb<=ub):
mid = (lb+ub)//2
if(search==lst[mid]):
res = True
print("Found at {}".format(mid+1))
break
elif(search>lst[mid]):
lb = mid+1
else:
ub = mid-1
if(res==False):
print("Not found")
lst.sort()
print(lst)
lb = 0
ub = len(lst)-1
res = False
while(lb<=ub):
mid = (lb+ub)//2
if(search==lst[mid]):
res = True
print("Found at {}".format(mid+1))
break
elif(search>lst[mid]):
lb = mid+1
else:
ub = mid-1
if(res==False):
print("Not found")