ISRO Computer Science (CSE) 2014 - Question 4

All ISRO Computer Science (CSE) papers | ISRO Computer Science (CSE) 2014

Consider the following pseudocode:\n```\nwhile (m < n)\n if (x > y) and (a < b) then\n a = a + 1\n y = y - 1\n end if\n m = m + 1\nend while\n```\nWhat is cyclomatic complexity of the above pseudocode?

  • A. 2
  • B. 3
  • C. 4
  • D. 5

Answer: C. 4

Explanation: Cyclomatic complexity $V(G) = P + 1$ where P is the number of predicate nodes.\nPredicates: `while(m<n)`, `if(x>y)`, `if(a<b)` (compound condition counts as 2 decisions or 1 depending on graph, but formula $V(G) = \text{Regions} = \text{Predicates} + 1$).\nHere conditions: 1 (while) + 2 (if with AND) = 3 predicates. $3+1 = 4$.

| | All questions of ISRO Computer Science (CSE) 2014