CS FundamentalsHardProduct-company placement · GATE CS

A function has three if-else statements in sequence, followed by a loop that runs either 0 or 1 time (decided by the input) and whose body is one if-else. How many distinct entry-to-exit paths does it have, and what is its cyclomatic complexity?

  1. A. 24 paths; V(G) = 6
  2. B. 32 paths; V(G) = 6
  3. C. 16 paths; V(G) = 5
  4. D. 24 paths; V(G) = 5

Correct answer: A. 24 paths; V(G) = 6

The three if-elses give 2³ = 8 combinations; the loop contributes 1 path for zero iterations plus 2 for one iteration, so 8 × 3 = 24 paths. Decisions are 3 ifs + loop + inner if = 5, so V(G) = 6. 32 treats the loop as a plain two-way branch with an independent if.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic