Let T(n) be the running time of function select_even. Find the equation of T(n) and find the complexity of T(n) using big-O notation.
def select_even(L):
output = []
for x in L:
if x%2==0:
output.append(x)
return output
def select_even(L): output = [] // 1 for x in L: // n if x%2==0: // k times. assuming there are k numbers in L list. output.append(x) // 1 return output // 1 if there are n elements in L list, and k elements in the list. x%2==0, indicates that x is even so, T(n) = 2 + n + k. we know that k <= n so, T(n) <= 2+n+n = 2+2n hence time complexity is O(n) Answer: O(n)
Let T(n) be the running time of function select_even. Find the equation of T(n) and find...
Let T(n) be the running time of function foo. Find the equation of T(n) and find the complexity of T(n) using big-O notation. def foo(L): s = 0 for x in L: j = len(L) while j > 1: j = j / 2 s = s + x print(s) return s
Question 3: Given the following two code fragments [2 Marks] (i)Find T(n), the time complexity (as operations count) in the worst case? (ii)Express the growth rate of the function in asymptotic notation in the closest bound possible. (iii)Prove that T(n) is Big O (g(n)) by the definition of Big O (iv)Prove that T(n) is (g(n)) by using limits
Find asymptotic running time , find expression for the running time as a function of n, then find valid upper and lower bound which differ by only a constant factor g) Func7(n) while (i 5n3) do 10n3 while 3) do s i j return 8 (h) Func8(n) for 1 to n do for i to n2 do for k j to n do s i -t- j return s (i) Func9(n) for i- 1 to n/2 do for j i...
Q6) let T(n) be a running time function defined recursively as 0, n=0 n=1 3T(n - 1)- 2T(n - 2), n> 1 a) Find a non-recursive formula for T(n) b) Prove by induction that your answer in part (a) is correct. c) Find a tight bound for T(n).
Big-O notation. Consider the following function. int func1(int n) { int sum = 0, i; for(i = 0; i<n; i++;) { sum += i; return sum; } Express the running time of func1 as a function of n using big-O notation. Write a function that has the same functionality as func1, but runs in O(1) time.
a) Prove that running time T(n)=n3+30n+1 is O(n3) [1 mark] b) Prove that running time T(n)=(n+30)(n+5) is O(n2) [1 mark] c) Count the number of primitive operation of algorithm unique1 on page 174 of textbook, give a big-Oh of this algorithm and prove it. [2 mark] d) Order the following function by asymptotic growth rate [2 mark] a. 4nlogn+2n b. 210 c. 3n+100logn d. n2+10n e. n3 f. nlogn
Question 1 (25 pts) Find the running time complexity for the following code fragments. Express your answers using either the Big-O or Big-Θ notations, and the tightest bound possible. Justify your answers. for(int count O , i -0; i < n* n; i++) for(int i0 ; j <i; j++) count++ for(int count O , i -0; i
What is the time-complexity of the algorithm abc? Procedure abc(n: integer) s := 0 i :=1 while i ≤ n s := s+1 i := 2*i return s consider the following algorithm: Procedure foo(n: integer) m := 1 for i := 1 to n for j :=1 to i2m:=m*1 return m c.) Find a formula that describes the number of operations the algorithm foo takes for every input n? d.)Express the running time complexity of foo using big-O/big-
Consider the following Python function: def find_max (L): max = 0 for x in L: if x > max: max = x return max Suppose list L has n elements. In asymptotic notation, determine the best case running time as function of n In asymptotic notation, determine the worst case running time as function of n Now, assume L is sorted. Give an algorithm that takes asymptotically less time than the above algorithm, but performs the same function. Prove that...
2. Give the asymptotic running time of each the following functions in e notation. That is, write down a recurrence relation for each recursive function below and solve it. Show your work def Pow(x, n): 2 if n-0: 3 return 1 end 5 e f Pow(x, [n/2]) 1 # n is even if n % 2-0: 9 return f f 10 end #nis odd 12return r*f*.f 13 end