4. Find a closed form, in terms of n, for the number of times S is executed in the following algorithm:
for i := 1 to n do
for j := i to n do
S
od
od
closed form of n for the above code is as below
: [n(n+1)]/2
As loop executes from 1 to n as two statements specifies same
4. Find a closed form, in terms of n, for the number of times S is...
Problem 1: Let W(n) be the number of times "whatsup" is printed by Algorithm WHATSUP (see below) on input n. Determine the asymptotic value of W(n). Algorithm WHATSUP (n: integer) fori1 to 2n do for j 1 to (i+1)2 do print("whatsup") Your solution must consist of the following steps: (a) First express W(n) using summation notation Σ (b) Next, give a closed-form formula for W(n). (A "closed-form formula" should be a simple arithmetio expression without any summation symbols.) (c) Finally,...
Need to find number of elementary expressions in terms of n, not looking for Big O complexity. 4. Work out the number of elementary operations in the worst possible case and the best possible case for the following algorithm (justify your answer): 0: function Nonsense (positive integer n) 1: it1 2: k + 2 while i<n do for j+ 1 to n do if j%5 = 0 then menin else while k <n do constant number C of elementary operations...
Find the worst case runtime f(n) for the following algorithms. Specify the number of operations executed for an input size n, for the worst case run time as a function of n. Circle statement(s) and draw a line to the right side specifying the number of operations. If statement(s) are a part of an iteration of n, specify the total number of iterations as a function of n. Algorithm-01 int sum = 0; int j = 1; while ( <=...
10 pts Question 2 Find 0 - notation (as a function of n) for the number of times the statement "x x +1" is executed in the following pseudocode: for i 1 to n3 for j 1 to i х%3Dх+1
1, Variation on 3.3#4] Give a big-O estimate in terms of n for the number of oper- ations used in this segment of an algorithm, where an operation is an addition or a multiplication, (ignoring comparisons used to test the conditions in the while loop). while i 〈 n j:= j + i [10 points]
A certain computer algorithm executes three times as many operations when it is run with an input of size n as when it is run with an input of size n -1 (where n > 1 is an integer). When the algorithm is run with an input of size 1, it executes ten operations. Let sn be the number of operations the algorithm executes when it is run on an input of size n. Find a closed form for s....
Question 20 Find a theta notation for the number of times the statement x = x + 1 is executed: 12 while i<n) 12 - - 1 02") (1) e(n) edign) On ign) edgign)
ALGORITHM X(A[0..n - 1]) // Input: A contains n real numbers for it 0 to n - 2 do for jt i +1 to n - 1 do if Aj] > A[i] swap A[i] and A[j] 1. What does this algorithm compute? 2. What is the basic operation? 3. How many times is the basic operation executed? 4. What is the efficiency class of this algorithm?
Suppose you have an array S indexed from 1 to n which contains n numbers, not in any particular order, and you wish to count how many times a given number x occurs in S. Consider the recursive algorithm below for this which finds the number of occurrences of x in the index range i...j in S. Of course, solving the problem would involve an initial call to the algorithm for the range 1.n: int CountOccur (int i,j) { int...
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;}