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...
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) +...
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 a big-Oh characterization, in terms of n,of the running time for each of the following code segments (use the drop-down): - public void func1(int n) { A. @(1). for (int i = n; i > 0; i--) { System.out.println(i); B. follogn). for (int j = 0; j <i; j++) System.out.println(j); c.e(n). System.out.println("Goodbye!"); D.@(nlogn). E.e(n). F.ein). public void func2 (int n) { for (int m=1; m <= n; m++) { system.out.println (m); i = n; while (i >0){ system.out.println(i); i...
Give the tightest bound in terms of Big O public type foo(n, a[]){ for (i=0, i<n; i++){ if (a[i] == 0) return 0; } return 1; }
(1) Give a formula for SUM{i} [i changes from i=a to i=n], where a is an integer between 1 and n. (2) Suppose Algorithm-1 does f(n) = n**2 + 4n steps in the worst case, and Algorithm-2 does g(n) = 29n + 3 steps in the worst case, for inputs of size n. For what input sizes is Algorithm-1 faster than Algorithm-2 (in the worst case)? (3) Prove or disprove: SUM{i**2} [where i changes from i=1 to i=n] ϵ tetha(n**2)....