Question: Assignment Objectives: (1) to practice Big-O Notation and (2) to practice writing a recursive function in Python. -What is the Big-O notation for the worst-case
Assignment Objectives: (1) to practice Big-O Notation and (2) to practice writing a recursive function in Python.
-What is the Big-O notation for the worst-case runtime of each of the following functions? Provide a brief explanation for each answer.
7. def function1(n):
i = n
k = 0
while i > 1:
k = k + i
i = i // 2
return k
Answer:
8. def function2(n):
k = 0
for i in range(n):
k = k + i
for j in range(n):
k = k - 1
return k
Answer:
9. def function3(n):
months = n * 12
days = n * 365
print (n, 'years =', months, 'months, or approx.', days, 'days.')
return
Answer:
10. def function4(n):
a=5
for i in range(n):
for j in range(n):
x = x * a
y = y * x
z = z * i
for k in range(n):
z = a * z + 45
z = z + 45
return z
Answer:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
