Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

understand possible effects of ethnicity;

Answered: 1 week ago