(g)
3i = n^2 for outer loop
=> 2log 3n
For outer loop
1 = n^3 / 5i for outer loop
=> 3log 5n
So overall time complexity is O(log 3n3log
5n)
(h) Outer for loop n times ,
the next for loop n^2 times itself and n times for outer loop so
n^3
the next for loop n^3 times itself and n^3 times for outer loop so
n^6
Time complexity is O(n6)
(i) Outer loop runs for n/2 time, Inner loop runs for n^2 - n + 1
times.
So overall time complexity is O(n^3)
(j) n times i.e O(n)
Thanks, let me know if there is any concern.
Find asymptotic running time , find expression for the running time as a function of n,...
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
Write a recurrence relation describing the worst case running time of each of the following algorithms, and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution by using substitution or a recursion tree. You may NOT use the Master Theorem. Simplify your answers, expressing them in a form such as O(nk) or (nklog n) whenever possible. If the algorithm takes exponential time, then just give an exponential lower bound using the 2 notation. function...
Analyze the running time of the following algorithms asymptotically. (a) Algorithm for-loop(n): P = 1 for i = 1 to 5n^2 do p = p times i return p (b) Algorithm for-loop(n): s = 0 for i = 1 to n do for j = I to n do s = s + i return s (c) Algorithm WhileLoop(n): x = 0; j = 2; while (j = n){x = x+ 1; j =j times 2;}
4. [10pts Find a tight asymptotic upper bound for the function T(n) defined by the recurence relation T(2)-2 T(n) = T(n/2) + Tuv )) + n Assume that n is a power of 2
For each of the following problems write a recurrence relation describing the running time of each of the following algorithms and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution using substitution and carefully computing lower and upper bounds for the sums. Simplify and express your answer as Θ(n k ) or Θ(n k (log n)) wherever possible. If the algorithm takes exponential time, then just give exponential lower bounds. 5. func5 (A,n) /*...
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
For each C++ function below, give the tightest can asymptotic upper bound that you can determine. (a) void mochalatte(int n) { for (int i = 0: i < n: i++) { count < < "iteration;" < < i < < end1: } } (b) void nanaimobar (int n) { for (int i = 1: i < 2*n: i = 2*i) { count < < "iteration;" < < i < < end1: } } void appletart (int n) { for (int...
Please give explanation as well ma E. Asymptotic Analysis rays For these problems, you should give a brief explanation as hws.txt. You should not use any fancy typesetting tools (like LaTeX, Word, etc.). Just submit a text file called hws.txt. You are not required to explain your solutions, but you are encouraged to do so. Provide simple and tight asymptotic bounds for each of the following. Here, "simple" means roughly "no unnecessary terms or constants' and "tight" means "either the...
Write a recurrence relation describing the worst-case running time of each of the following algorithms and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution by using substitution or a recursion tree. You may NOT use the Master Theorem. 上午1:46 3月21日周四 令52%. " 5. endfor 6. return (r); function func4(A, n) *Aarray of n integers */ 1. if n s 20 then return (A[n]); 4. while (i < n/2) do 7. endwhile 8. x...
Exercise 7.3.5: Worst-case time complexity - mystery algorithm. The algorithm below makes some changes to an input sequence of numbers. MysteryAlgorithm Input: a1, a2....,an n, the length of the sequence. p, a number Output: ?? i != 1 j:=n While (i < j) While (i <j and a < p) i:= i + 1 End-while While (i <j and a 2 p) j:=j-1 End-while If (i < j), swap a, and a End-while Return( aj, a2,...,an) (a) Describe in English...