#Binary Search
def binary_search(List,value): # The search function Definition
middle=0 # Intial value of the middle element
start=0 # Initial value always 0
end=len(List) # length of the list
steps=0
if(value in List):
while(start<= end): # iterate until last element
print("Step : ",steps+1,": ",str(List[start:end+1]))
steps+=1
middle=(start+end)//2
if value==List[middle]:
return middle
elif value < List[middle]:
end = middle-1
else:
start=middle+1
return -1
# Show the number
print(value)
elements=[ ]
n=int(input("Enter the number of elements: "))
print("Enter the elements one by one")
for i in range(0,n):
numbers=int(input())
elements.append(numbers)
target=int(input("Enter the element to search"))
if(target not in elements):
print("Element not in the list...!!!")
binary_search(elements,target)