Consider the following pseudo-code: I = 0; J = 0; K = 8; while (I < K – 1)…
2020
Consider the following pseudo-code:
I = 0; J = 0; K = 8;
while (I < K – 1) //while-1
{
J = J + 1;
while (J < K) //while-2
{
if (x[I] < x[J])
{
temp = x[I];
x[I] = x[J];
x[J] = temp;
}
} // end of while-2
I = I +1;
} // end of while-1 The cyclomatic complexity of the above is
- A.
3
- B.
2
- C.
4
- D.
1
Attempted by 42 students.
Show answer & explanation
Correct answer: C
To calculate the cyclomatic complexity, count the decision points in the control flow graph. The code has two while loops and one if statement, totaling 3 decision points. Using the formula V(G) = Decision Points + 1, the complexity is 3 + 1 = 4.