This is a program to perform Binary Search on a sorted array
In [41]:
A = []
A = input("Input a sorted array ")
n = input("Enter number to be searched ")
In [42]:
m1 = 0
m2 = len(A) - 1
while m1 <= m2:
mid = int((m1 + m2) / 2)
if A[mid] == n:
print(n, "found")
break;
elif A[mid] > n:
m2 = mid - 1
else:
m1 = mid + 1
if m2 < m1:
print(n, "not found")