ISRO Scientist/Engineer CSE 2020Information Systems and Software Engineering › Software Testing and Complexity Metrics
ISRO Scientist/Engineer CSE 2020 PYQ: 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 {…
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
- A3
- B2
- C4Correct answer
- D1
Answer
(C) $4$
Approach
Cyclomatic complexity counts the number of linearly independent paths through a program. For structured code, it equals 1 plus the number of decision points (each if, while, for, etc.). Here there are two while loops and one if statement, giving 1 + 3 = 4.
Reviewed by ISRO IQ Editorial Team.