The cyclomatic complexity of a flow graph V(G), in terms of predicate nodes is…
2016
The cyclomatic complexity of a flow graph V(G), in terms of predicate nodes is :
(1) P + 1 (2) P – 1
(3) P – 2 (4) P + 2
Where P is number of predicate nodes in flow graph V(G).
- A.
(1)
- B.
(2)
- C.
(3)
- D.
(4)
Attempted by 79 students.
Show answer & explanation
Correct answer: A
Correct formula: V(G) = P + 1, where P is the number of predicate (decision) nodes.
Reasoning:
Base case: If there are no predicate nodes (P = 0), there is exactly one independent path through the program, so V(G) = 1.
Each predicate (decision) node introduces one additional independent path (it creates a branching point), so each predicate increases cyclomatic complexity by 1.
Therefore, starting from 1 when P = 0 and adding one for each predicate gives V(G) = P + 1.
Quick example: If P = 2 decision nodes, then V(G) = 2 + 1 = 3 independent paths.
Note: This aligns with McCabe's general formula V(G) = E − N + 2 for a single connected flow graph; for typical structured program flow graphs this simplifies to counting predicate nodes and adding one.
A video solution is available for this question — log in and enroll to watch it.