Question: def binary_search(lst, to_find): def binary_search_rec(bot, top): if bot > top: return None mid = (bot + top) // 2 if to_find == lst[mid]: return lst[mid]

def binary_search(lst, to_find):

def binary_search_rec(bot, top):

if bot > top:

return None

mid = (bot + top) // 2

if to_find == lst[mid]:

return lst[mid]

elif to_find < lst[mid]:

return binary_search_rec(bot, mid-1)

else:

return binary_search_rec(mid+1, top)

return binary_search_rec(0, len(lst)-1)

Given the call binary_search([2, 5, 7, 9, 13, 22], 22), which values (in order) in lst are compared to to_find before returning from the call?

5 9 13 22 (b) 9 22 (c) 7 13 22 (d) 7 9 22

Which of the following correctly removes the element at position idx from an arraybacked list?

1. for i in range(len(self.data)-1, idx, -1):

self.data[i-1] = self.data[i]

2. for i in range(idx):

self.data[i] = self.data[i+1]

3. for i in range(0, idx-1, 1):

self.data[i+1] = self.data[i]

4. for i in range(idx, len(self.data)-1):

self.data[i] = self.data[i+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!