N is the number of nodes of the control flow graph and E is the number of…
2021
N is the number of nodes of the control flow graph and E is the number of edges in the control flow graph. What is McCabe’s cyclomatic complexity V(G)?
- A.
V(G) = E + N + 2
- B.
V(G) = E − N + 2
- C.
V(G) = E + N − 2
- D.
V(G) = E − N − 2
Attempted by 349 students.
Show answer & explanation
Correct answer: B
McCabe’s cyclomatic complexity V(G) is a measure of the number of linearly independent paths in a program’s control flow graph. It is calculated using the formula:
V(G) = E - N + 2
Where: E = number of edges in the control flow graph, N = number of nodes in the control flow graph.
This formula is derived from graph theory, where the complexity represents the number of regions in the graph. The +2 accounts for the entry and exit points of the control flow.