Skip to content

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

  1. A
    3
  2. B
    2
  3. C
    4
    Correct answer
  4. D
    1

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.