Question: How do I use binary search in python to find the minimum of a list (not sorted)? I want to write a function called findmin

How do I use binary search in python to find the minimum of a list (not sorted)?

I want to write a function called findmin with parameters of a list and a variable k, which is assumed to be a constant. The items in the list repeat at most k times, and the function should return the minimum element, NOT its index. The default value of k is 1.

Notes:

A list L is non-increasing if L[i] >= L[i+1] for all i . Similarly, a list in non-decreasing if L[i] <= L[i+1] for all i . These definitions allow L[i] == L[i+1] .

L should be able to be broken into 2 parts: L[:k] (non-increasing) and L[k:](non-decreasing)

Ex: findmin([5,4,4,4,2,2,1,0,6,7,8,9],3)

the output should be 0

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!