Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you help me to revise itthank you Write a python function to do a binary search in a list and return True if the

Could you help me to revise itthank you
image text in transcribed
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 half in which the target cannot lie is eliminated and the search continues on the remaining half, again taking the middle element to compare to the target value, and repeating this untl the target value is found. If the search ends with the remaining half being empty, the 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 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 123] def binarysearch(L, element): lower upper len(L) while lower val: if lowerx break lower-x elif elenent

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

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

Students also viewed these Databases questions

Question

Who is ultimately responsible for the creative product? LO.1

Answered: 1 week ago