Question: Python Add two assignment statements at the places marked, so that this function works correctly. ########################################################################### def binsearch(L, i, x): '''Assuming L[0:i] is sorted and

Python

Add two assignment statements at the places marked, so that this function works correctly. ###########################################################################

def binsearch(L, i, x): '''Assuming L[0:i] is sorted and 0 =>=> return j such that 0 =>=>=> j = 0 hi = i while j != hi: # invariant: L[0:j] =>=> mid = (hi + j) // 2 if x

pass # TO DO

else: pass # TO DO

return j

def testBinSearch(): assert binsearch([0,2,4,6,3,0,5], 3, 3) == 2 assert binsearch([1,2,3,4,1], 3, 1) == 1 assert binsearch([1,2,3,0], 3, 2) == 2 assert binsearch([1,3,5,5], 3, 6) == 3 assert binsearch([1,3,5,5], 4, 6) == 4 assert binsearch([0], 1, 5) == 1 assert binsearch([3,4], 2, 5) == 2 assert binsearch([5], 1, 2) == 0 assert binsearch([3,4], 2, 1) == 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 Programming Questions!