Question
I need help for the order of growth for functions in Python 3. Please show instruction for each questions how you solved Thank you. Q3:
I need help for the order of growth for functions in Python 3. Please show instruction for each questions how you solved Thank you.
Q3: What is the order of growth for the following functions?
Kinds of Growth
Here are some common orders of growth, ranked from no growth to fastest growth:
1. (1) constant time takes the same amount of time regardless of input size
2. (log n) logarithmic time
3. (n) linear time
4. (n log n) linearithmic time
5. (n2 )
6. (n3 )
7. (n4 )
8. (n5 )
9. (n6 )
10. (n7 ), etc. polynomial time
11. (2n), (3n), etc. exponential time (considered intractable; these are really, really horrible)
12. Something else not listed
You should create a parameter-free function called complexity and return a list with 5 numbers. You should put the corresponding growth rate (1-12) for each of the problems listed below.
Question 3.1
def foo(n): s = 0
for i in range(1, n):
for j in range(0, i*i):
for t in range(0, j):
s = s + i + j + t
Question 3.2
Calculate the complexity for sum_facts(n).
def factorial(n):
i, prod = 1, 1
while i <= n:
prod = prod * i
i = i + 1
return prod
def sum_facts(n):
sum, i = 0, 1
while i <= n:
sum += factorial(i)
i = i + 1
return sum
Question 3.3
def foo(n): i = 1 while i < n:
for j in range(i, i+2):
print(i)
i = i + 2
Question 3.4
def foo(n): if n==0:
return 1
else:
return 2 + foo(n//2)
Question 3.5
def foo(n):
i = n
while i > 1:
j = 1
while j < n:
k = 0
while k < n:
k = k + 2
j = j * 2
i = i //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