Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
image text in transcribed
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 can't 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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

ethical and moral values in reciprocal relationships;

Answered: 1 week ago

Question

2. Provide recommendations for effective on-the-job training.

Answered: 1 week ago