Cyclomatic complexity of the flow graph given below is __________.

2026

Cyclomatic complexity of the flow graph given below is __________.

image.png

Answer: D. 3Cyclomatic complexity, V(G), of a control-flow graph counts the number of linearly independent paths through it. For a graph with N nodes and E edges, V(G) =…

  1. A.

    5

  2. B.

    6

  3. C.

    4

  4. D.

    3

Attempted by 131 students.

Show answer & explanation

Correct answer: D

Cyclomatic complexity, V(G), of a control-flow graph counts the number of linearly independent paths through it. For a graph with N nodes and E edges, V(G) = E − N + 2 always applies directly, regardless of how many exit (terminal) nodes the graph has. This is equivalent to counting the number of regions in the graph's planar layout, including the unbounded outer region. A common shortcut counts decision (predicate) nodes — nodes with more than one outgoing edge — and adds 1: V(G) = D + 1. That shortcut, however, is valid only when the graph has exactly ONE exit node; for a graph with D decision nodes and X exit nodes in general, V(G) = D − X + 2.

  1. Count the nodes and edges exactly as drawn. There are N = 11 nodes (1 through 11). Tracing every arrow — 1→2, 2→3, 2→4, 3→5, 3→6, 5→9, 6→9, 4→7, 4→8, 7→10, 8→10, 10→11 — gives E = 12 edges.

  2. Identify the exit (terminal) nodes: those with no outgoing edge. Node 9 (reached from 5 and 6) and node 11 (reached from 10) both have no further arrows leaving them, so this graph has X = 2 exit nodes.

  3. Identify the decision nodes: those with more than one outgoing edge. Nodes 2, 3, and 4 each branch into two paths, so D = 3.

  4. Apply V(G) = E − N + 2 directly to the graph as drawn: V(G) = 12 − 11 + 2 = 3.

  5. Cross-check with the general decision-node relation V(G) = D − X + 2: V(G) = 3 − 2 + 2 = 3 — the same result.

As an independent check, count the regions of the graph's planar layout: the two enclosed regions bounded by 3-5-9-6 and by 4-7-10-8, plus the single unbounded outer region, give 3 regions in total, confirming V(G) = 3. Note that the simplified single-exit shortcut V(G) = D + 1 = 3 + 1 = 4 does not apply directly here, because it assumes exactly one exit node, while this graph has two (nodes 9 and 11).

Explore the full course: Up Lt Grade Assistant Teacher 2025

Loading lesson…