12. Write a function that takes an array of 10 integers and a number as an argument
and displays the position of the number using binary search
Answers
Answered by
0
Explanation:
def binary_serach(arr,x):
low = 0
high = len(arr)-1
mid = 0
while high>=low:
mid = (high+low)//2
if arr[mid]>x:
low = mid+1
elif arr[mid]<x:
low = mid-1
else:
return mid
else:
return -1
arr = list(eval(input("Enter array of 10")))
x = init(input("Enter no to find index"))
binary_search(arr,x)
MARK ME AS BRAINLY
Similar questions