Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help for the order of growth for functions in Python 3. Q1: What is the order of growth for the following functions? Kinds

I need help for the order of growth for functions in Python 3.

Q1: 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 ), etc. polynomial time

7. (2n), (3n), etc. exponential time (considered intractable; these are really, really horrible)

8. Something else not listed

You should create a parameter-free function called question1 and return a list with 10 numbers. You should put the corresponding growth rate (1-8) for each of the problems listed below

Question 1.5

def func(n): i = 1 sum = 0 while i <= n: sum = sum * i i = i * 5 return sum

Question 1.6

def mod_10(n): if n % 10 == 0: return 10 else: return 1 + mod_10(n-1)

Question 1.7

Calculate the complexity for foo(bar(n)). To see pattern I'd suggest you to take different inputs for n and write down the recursion tree.

def bar(n): if n%2 == 1: return n + 1 return n def foo(n): if n < 1: return 2 if n % 2 == 0: return foo(n-1) + foo(n-2) else: return 1 + foo(n-2)

Question 1.8

def func(alist): for num in range(len(alist)-1,0,-1): for i in range(num): if alist[i] > alist[i+1]: alist[i], alist[i+1] = alist[i+1], alist[i]

Question 1.9

def func(n): for i in range(0,n): for j in range (i+1, i, -1): for k in range(n, j, -1): print("print")

Question 1.10

Calculate the complexity for second(n).

def first(n): for i in range(0, n): print("one") def second(n): for i in range(0, n): first(n)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions