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