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
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