We all know that Time Complexity of a loop is considered as O(Logn) if the loop variables is divided / multiplied by a constant amount.
Here the loop will stop when i >= n. If we let k be some arbitrary iteration of the loop, the value of i on iteration k will be 4k. The loop stops when 4k > n, which happens when k > log4 n. Therefore, the number of iterations is only O(log n), so the big O estimate in terms of n is O(log n).
1, Variation on 3.3#4] Give a big-O estimate in terms of n for the number of...
Problem 7. Give a big-O estimate for the number of operations where an operation is an addition or a multiplication, used in this segment of an algorithm (ignoring comparisons used to test the conditions in the vhile loop. while i Sn do end while
Give a big-O estimate for the number of additions ued in the segment of an algorithm below. t:=0 for i := 1 to n for j := 1 to n t := t + i + j
consider this segment of an algorithm: for i := 1 ton n for j:=1 to n top:=ij+j+10 a. find a function f(n) that counts the number of multiplication and additions performed in this segment. b. Give a big O estimate for the number of additions and multiplications used in the segment
1. Give the big-O characterization of the following loops, in terms of parameter n, and justify your answer: a) for (int i=1; i<=n, i++) {for (int j=1; j<=n; j++) {a constant-time operation}} b) for (int i=1;i<=n, i++) {for (int i=1; j<=i; j++) {a constant-time operation}} c) for (int i=1;i<=n*n, i++) {for (int j=1; j<=n; j++) {a constant-time operation }} d) for (int i=1; i<=n*n, i++) {for (int j=1; j<=i; j++) {a constant-time operation }} e) for (int i=1; i<=n, i++)...
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...
. Big O Notation.Thanks to Reges, Building Java Programs, 2nd edition. Estimate the big-O complexity for each of these algorithms, and justify your answer. To confirm your calculations, answers are provided at the end of the rubric. Your justification can be mathematical or written, formal or informal. Rubric: Correct Big-O classification of four problems Justification of four problems Big-O categories: 3.1. O(log n). 3.2. O(n). 3.3. O(n2). 3.4. O(1) Problem Code fragment 3.1 int sum = 0; int j =...
Analyze the following code and provide a "Big-O" estimate of its running time in terms of n. Explain your analysis. Assume k is a constant given by the problem. for (i=1; i<=n; i++) p = pow(i,k); // p = i to the power of k for (j=1; j<=p; j++) Some O(1) work end for end for
Prove Big O in terms of nₒ and C? There are 5 examples: class Exercise { public static int example1(int[] arr) { int n = arr.length, total = 0; for (int j=0; j < n; j++) // loop from 0 to n-1 total += arr[j]; return total; } public static int example2(int[] arr) { int n = arr.length, total = 0; for (int j=0; j < n; j += 2) // note the increment of 2 total += arr[j]; return...
Give the tightest bound in terms of Big O public type something(n){ result = 0; while (n > 1){ n /= 2; result += 1; } return result; }
Discrete Math
Give a big-Theta estimate for the number of additions in the following algorithm a) procedure f (n: integer) bar = 0; for i = 1 to n^3 for j = 1 to n^2 bar = bar + i + j return bar b) Consider the procedure T given below. procedure T (n: positive integer) if n = 1 return 2 for i = 1 to n^3 x = x + x + x return T(/4) + T(/4) +...