Let T(n) represent the total execution time of a loop for which the loop test is true n times (i.e., the loop body will execute n times). For each possible value of T(n) listed below, give a tight upper bound for the time cost (in terms of O(…)) of one execution of the loop body (denote this by L(n)) that makes the statement true. Answer each part separately. Each answer should be of the form L(n) = O(…)
a. T(n) = O(n2 )
b. T(n) = O(n)
c. T(n) = O (n lg n)
Since the loop will be true n times
So, the net complexity will become n times too
So,
A)
L(n)=O(n^3)
B)
L(n)=O(n^2)
C)
L(n)=O(n^2*log(n))
Let T(n) represent the total execution time of a loop for which the loop test is...
Let f(n) = 5n^2. Prove that f(n) = O(n^3). Let f(n) = 7n^2. Prove that f(n) = Ω(n). Let f(n) = 3n. Prove that f(n) =ꙍ (√n). Let f(n) = 3n+2. Prove that f(n) = Θ (n). Let k > 0 and c > 0 be any positive constants. Prove that (n + k)c = O(nc). Prove that lg(n!) = O(n lg n). Let g(n) = log10(n). Prove that g(n) = Θ(lg n). (hint: ???? ? = ???? ?)???? ?...
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).
Let P(t) represent the number of people who, at time t, are infected with a certain disease. Let N denote the total number of people in the population. Assume that the spread of the disease can be modeled by the initial value problem: dP/dt = k(N − P)P, P(0) = P0. At time t = 0, when 100,000 member of a population of 500,000 are known to be infected, medical authorities intervene with medical treatment. As a consequence of this...
Let G (V, E) be a directed graph with n vertices and m edges. It is known that in dfsTrace of G the function dfs is called n times, once for each vertex It is also seen that dfs contains a loop whose body gets executed while visiting v once for each vertex w adjacent to v; that is the body gets executed once for each edge (v, w). In the worst case there are n adjacent vertices. What do...
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
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
A rectangular loop of wire with dimensions and w is released from rest at time t = 0 from a region with zero magnetic field into a region with uniform magnetic field Bo pointing into the page. At t=0, the upper edge of the loop is in the zero field region and the lower edge is in the uniform field region as shown in the figure below. The loop has mass m and the acceleration due to gravity is g...
6. Let T(1..n] be a sorted array of distinct integers, some of which may be negative. Give an algorithm that can find an index i such that 1 <i<n and T[i] = i, provided such an index exists. Your algorithm should take a time in O(lg n) in the worst case. Answers must be proven (or at least well justified)
Question2 0/5 pts If exact running time of an algorithm is T(n)-5n3+ n2 + 3n -5 where n is the input size, then which of the following is true? T(n)- O(n) RCOECEQuestion 3 0/5 pts Which of the following is the correct ranking of the functions listed below: logn. n2 n2n, 2. 1500. nlogn, 5 Question 4 5/5 pts to search
The flow system shown in the figure is activated at time t = 0. Let Qi(t) denote the amount of solute present in the ith tank at time t. Assume that all the flow rates are a constant 10 L/min. It follows that the volume of solution in each tank remains constant; assume this volume to be 1000 L. The concentration of solute in the inflow to Tank 1 (from a source other than Tank 2) is 0.2 kg/L, and...