1. Engineering
  2. Computer Science
  3. question 2 binary search 2 points write a python function...

Question: question 2 binary search 2 points write a python function...

Question details

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 the array. If they are not equal, the hailf in which the target cannot lie is eliminated and the search continues on the remaining hailf, again taking the middle 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, the target is not in the array. The input ist may not be sorted. Assume the input list is non-empty Your code must be an implementation of the binary search algorithm, In particular, you cant just return result by using built-in functios 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 17) def binarysearch(L, element) a-o
Write a function pairsum(1, n) that determines if there are any two numbers in the list 1 that add to n For example: pairSum(11, 2, 31, 5) should return True, since 2 +3 5 pairSum(, 2, 3, 6) should return False since there are no two numbers that add to 6 pairSun((1, 2, 3, 31, 6),should return True because there are two 3s in the list which sum is 6 MIn t 1 def pairsum(1, n)
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution