Computer Science, asked by tishir22, 9 months ago

Write a program to perform binary search on a list of integers given below, to search for an element input by the user. If it is found, display the element along with its position, otherwise display the message “Search element not found”. 5, 7, 9, 11, 15, 20, 30, 45, 89, 97​

Answers

Answered by Anonymous
1

Answer:

hi...

Explanation:

# resursive function for binary search using python

def binary_search(l,ele,low,high):

   if low<=high:

       mid=(low+high)//2

       if l[mid]==ele:

           return mid

       elif ele<l[mid]:

           high = mid-1

           return binary_search(l,ele,low,mid)

       else:

           return binary_search(l,ele,low,high)

   else:

       return None

# main

my_list=eval(input("enter the list"))

ele=int(input("enter the list element to be searched for"))

l=int(input("enter the lowest index of the list"))

h=int(input("enter the highest index of the list"))

pos=binary_search(my_list,ele,l,h)

if pos!=None:

   print("element is found in the position",pos)

else:

   print("the element that you have searched for is not found in the list you have given")

#hope it helps you

please mark brainliest

Similar questions