Question: Do as basic Binary Search algorithm in Python 3 for a sorted sequence of numbers. For lists of even size, the middle index is the

Do as basic Binary Search algorithm in Python 3 for a sorted sequence of numbers.

For lists of even size, the middle index is the previous of the two middle elements. For example, if the given list is

[0, 1, 2, 3], then the middle element would be 1 and not 2.

Where binary_search(list,item)

returns the index of the target value item if it is found in the given list.

return the index the value would be at if it were inserted in order, if item is not found in the given list. <------- more important

>>>list = [1, 4, 5, 8, 11, 15] >>>binary_search(list,5) 2 <---found >>>binary_search(list,9) 4

>>>binary_search(list,0) -1

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!