Question: Complexity: Code Runtime You should create a parameter-free function called question1_2 and return a list with 10 numbers. You should put the corresponding growth rate





Complexity: Code Runtime You should create a parameter-free function called question1_2 and return a list with 10 numbers. You should put the corresponding growth rate (1 - 7) for each of the problems listed below. For example: Sample Question: for i in range(5, n+1): sum = sum + 1 Answer: 3 (linear time) Kinds of Growth Here are some common orders of growth, ranked from no growth to fastest growth: 1. 0(1) - constant time takes the same amount of time regardless of input size 2. O(log n) logarithmic time 3. O(n) linear time 4. O(n log n) linearithmic time 5. O(n) 6. O(n), etc. polynomial time 7. O(2), O(34), etc. exponential time considered intractable"; these are really, really horrible) Question 1.205 def func(lst): for i in range (len (lst)): min_idx = i for j in range (i+1, len (1st)): if lst[min_idx] > Ist[j]: min_idx = j 1st[i], lst[min_idx] = lst[min idx], lst[i] Question 1.206 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("done!") Question 1.207 Calculate the complexity for method_b (n). def method_a (n): for i in range (0, n): print ("in method_a") print (n) def method_b (n): for i in range (0, nin): method_a (n) Question 1.208 def func(n): i = 1 j = n while i =1): print ("again") print ("and again") j = j7/2 i = i + 2 Complexity: Code Runtime You should create a parameter-free function called question1_2 and return a list with 10 numbers. You should put the corresponding growth rate (1 - 7) for each of the problems listed below. For example: Sample Question: for i in range(5, n+1): sum = sum + 1 Answer: 3 (linear time) Kinds of Growth Here are some common orders of growth, ranked from no growth to fastest growth: 1. 0(1) - constant time takes the same amount of time regardless of input size 2. O(log n) logarithmic time 3. O(n) linear time 4. O(n log n) linearithmic time 5. O(n) 6. O(n), etc. polynomial time 7. O(2), O(34), etc. exponential time considered intractable"; these are really, really horrible) Question 1.205 def func(lst): for i in range (len (lst)): min_idx = i for j in range (i+1, len (1st)): if lst[min_idx] > Ist[j]: min_idx = j 1st[i], lst[min_idx] = lst[min idx], lst[i] Question 1.206 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("done!") Question 1.207 Calculate the complexity for method_b (n). def method_a (n): for i in range (0, n): print ("in method_a") print (n) def method_b (n): for i in range (0, nin): method_a (n) Question 1.208 def func(n): i = 1 j = n while i =1): print ("again") print ("and again") j = j7/2 i = i + 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
