What is the Cyclomatic Complexity for the following pseudo-code fragment?
i=1;
n=10;
while (i<n) do
j=i+1;
while (j<n) do
if A[i]<A[j] then
swap(A[i], A[j]);
end if
end while;
i=i+1;
end while;
CC = E – N + 2P
E = number of edges (transfers in control)
N = number of nodes
P = number of disconnected parts of the flow graph (e.g. a calling program and a subroutine)
Flow graph for this program will be

number of nodes =N= 7
number of edges=E=9
number of disconnected part of flow graph=P=1
Cyclomatic Complexity= E-N+2P
= 9-7+2(1)
= 4
NODE 1,2,3 ARE CONDITION NODES
What is the Cyclomatic Complexity for the following pseudo-code fragment? i=1; n=10; while (i<n) do ...
What is the cyclomatic complexity of the following pseudo code program segment? Use line numbers in the left column to indicate independent paths. Hint: Draw a flowchart and draw execution lines through the flowchart. 1) Read (A, B) 2) If (A>B) 3) Print A 4) Else 5) Print B 6) While (A>B) 7) A = A-1 8) End
c++ What is the worst-case complexity of the following code fragment: for(i = 0; i < N; i++) { for(j = 0; j < N; j++) { sequence of constant time statements } } for(i = N; i > 0; i--) { sequence of constant time statements }
What are the Big-Oh and Omega orders of the following code fragment? What is Tilde approximation? The fragment is prameterized on the variable n. Assume that you are measuring the number of swap calls. for(int j=0;j<n-1;j++){ int z = j; for (int i=j+1; i<n; i++){ if(a[i] < a[z]){ z=i;} } if(z!= j){ swap(a[j], a[z]); //count these } }
2. What is the output of the following code fragment? n = 1; while (n <= 5) { n++; cout << n << ' '; a.1 2 3 4 5 b. 1 2 3 4 c. 1 1 1 forever d. 2 3 4 5 e. 2 3 4 5 6 3. What is the termination condition for the following While loop? while (beta > 0 && beta < 10) { cout << beta << endl; cin >> beta; }...
Consider the following pseudo-code: // Assume i, j, k are integers for i = 1 to n do for j = n-i+1 to n { k = 1; while (k*k <= j) { perform <op>; k = k + 1; } } Find an expression for f(n), the number of times is performed. Find g(n) so that f(n) is Θ(g(n)). Prove your answer.
1(5 pts): For each code fragment below, give the complexity of the algorithm (O or Θ). Give the tightest possible upper bound as the input size variable increases. The input size variable in these questions is exclusively n. Complexity Code public static int recursiveFunction (int n)f f( n <= 0 ) return 0; return recursiveFunction (n - 1) 1; for(int i 0i <n; i+) j=0; for ( int j k=0; i; k < < j++) for (int j; m <...
What is the output of the following code fragment? int i = 1; while( i <= 5 ) if(i == 2 || i == 4) System.out.println(i + ":" + " is an even index) System.out.println("i: " + i); i++;
What is the Big-Oh order of the following code fragment? The fragment is parametrized on the variable N. Assume that you are measuring the number of times j is decremented. public static void sort(Comparable[] a) { int N-a.length; for (int i = 1; i < N;i++) { for (int j = i; j > && less(a[5], a[j-1]); j--) //measure j -- exch(a, j, j-1); O(nlogn) O O(n^2) Q(n) Does not exist.
What is the complexity of the following nested loops? for i = n to 1 step -1 do j ← i while j ≥ 1 Θ(j) statement j ← ëj/2û endwhile endfor
Please use induction
Consider the following code fragment: int i -1; int s=1; while (i <- n) Show that at the start of every iteration holds using induction