Question: what is the worst-case run-time complexity of the following function? def f_15(lst): # lst is a Python list res = 0 for x in lst:

what is the worst-case run-time complexity of the following function?

def f_15(lst): # lst is a Python list

res = 0

for x in lst:

res += res

return res

(a) O(1)

(b) O(log N)

(c) O(N)

(d) O(N^2)

def f_16(lst): # lst is a Python list

res = 0

for x in range(100):

res += lst[randrange(len(lst))]

return res

(a) O(1)

(b) O(log N)

(c) O(N)

(d) O(N^2)

def f_17(lst): # lst is a Python list

res = 0 bot, top = 0, len(lst)

while bot < top:

mid = (bot + top) // 2

res += lst[mid]

if res < 0:

bot = mid + 1

else:

top = mid - 1

return res

(a) O(1)

(b) O(log N)

(c) O(N)

(d) O(N^2)

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!