The cyclomatic complexity of the following graph is –

2021

The cyclomatic complexity of the following graph is –

Directed graph with vertices a, b, c, d, e and f

Answer: B. 5Concept. McCabe's cyclomatic complexity V(G) counts the linearly independent paths through a program graph. For a graph with E edges, N nodes and P connected…

  1. A.

    4

  2. B.

    5

  3. C.

    7

  4. D.

    6

Attempted by 260 students.

Show answer & explanation

Correct answer: B

Concept. McCabe's cyclomatic complexity V(G) counts the linearly independent paths through a program graph. For a graph with E edges, N nodes and P connected components, V(G) = E − N + 2P, which becomes V(G) = E − N + 2 when the graph is a single connected component. Equivalently, a planar drawing of such a graph is divided into exactly V(G) regions, counting the unbounded outer region.

Applying this to the graph shown.

  1. Count the nodes. The vertices drawn are a, b, c, d, e and f, so N = 6.

  2. Count the edges, one per arrow: a → b, a → c, c → b, c → e, b → d, d → b, e → d, e → f and f → d. The vertices b and d are joined by two arrows pointing opposite ways, and each arrow is its own edge, so E = 9.

  3. The whole drawing is one connected component, so P = 1 and the formula reduces to V(G) = E − N + 2.

  4. Substitute the counts: V(G) = 9 − 6 + 2 = 5.

Cross-check by regions. The drawing has no crossing lines, so its regions can be counted directly: the a-b-c cycle, the two-arrow loop between b and d, the area bounded by b, c, e and d, and the d-e-f cycle give 4 bounded regions, and the outer region makes 5. The cycle-space form (E − N + 1) + 1 = (9 − 6 + 1) + 1 = 5 agrees.

A common slip. Reading the two arrows between b and d as a single edge gives E = 8 and V(G) = 8 − 6 + 2 = 4, so each arrow must be counted separately.

Hence the cyclomatic complexity of the graph is 5.

Explore the full course: Up Lt Grade Assistant Teacher 2025

Loading lesson…