Question: Could you use sortto write this oneThank you Question 2: Binary search (2 points) Write a python function to do a binary search in a

Could you use sortto write this oneThank you  Could you use sortto write this oneThank you Question 2: Binary

Question 2: Binary search (2 points) Write a python function to do a binary search in a list and return True if the target element is in the list, else return False. Binary search is a search algorithm that finds if a target value is in a sorted list. Binary search compares the target value to the middle element of array. li they are not equal, the half in which the target cannot lie is eliminated and the search continues on the remaining half, agaln taking the mi element to compare to the target value, and repeating this until the target value is found. If the search ends with the remaining half being empty, t target is not in the array The input list may not be sorted. Assume the input list is non-empty Your code must be an implementation of the binary search algorithmIn particular, you can't ust return esult by using built-in functi s such as find, index, count and related functions. You are also not allowed to import libraries. Doing so will result in zero mark to this question. In [11: def binarysearch(L, element) # Your code here In 121: binarysearch(t1, 3, 23, 6, 7, 2, 91,9)--True Traceback (most recent call last) Typetrror ( 1 binarysearch(, 3, 23, 6,7, 2, 91,9) True cipython-input-1-555e32a58e17> in binarysearch(L, lement) while lowercupper m. ( lower + upper ) // 2 if L(m)-element: return True elif L(m)element : TypeErrors 'list' object is not callable In [25]1 binarysearch([1, 2, 3],4)--False

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!