Answered step by step
Verified Expert Solution
Question
1 Approved Answer
what is the big-O performance of the below functions? 1. def sum(n): k = 0 for i in range(n): k = k + i for
what is the big-O performance of the below functions?
1.
def sum(n):
k = 0
for i in range(n):
k = k + i
for j in range (n):
k = k - 1
return k
2.
def printTime(n) :
months = n * 12
days = n * 365
print (n, 'years = ' , months, 'months, or approx.', days, 'days.')
return
3.
def sum2(n):
i = n
k = 0
while i > 1:
k = k + i
i = i // 2
return k
4.
def mult(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
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