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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started