Consider the following pseudo code while (m < n) if (x > y ) and (a < b) then…

2014

Consider the following pseudo code

while (m < n)
   if (x > y ) and (a < b) then
      a=a+1
      y=y-1
   end if
   m=m+1 
end while 

What is cyclomatic complexity of the above pseudo code?

  1. A.

    2

  2. B.

    3

  3. C.

    4

  4. D.

    5

Attempted by 46 students.

Show answer & explanation

Correct answer: C

Cyclomatic complexity V(G) is calculated using the formula V(G) = P + 1, where P represents the number of decision points (predicate nodes) in the control flow graph. In this pseudo code, there are three decision points: 1) The while loop condition (m < n), 2) The first part of the if statement condition (x > y), and 3) The second part of the if statement condition (a < b). Note that compound boolean conditions joined by and count as separate decision nodes. Therefore, P = 3. Calculating the complexity: V(G) = 3 + 1 = 4.

Explore the full course: Isro