nerdexam
iSQI

CTAL-TTA_001 · Question #26

Which of the following is a valid way to calculate the cyclomatic complexity? 1 credit [K2]

The correct answer is D. Links - Nodes + 2. Option D is correct because cyclomatic complexity is defined by McCabe's formula: M = E − N + 2P, where E = edges (links), N = nodes, and P = connected components (typically 1 for a single program), reducing to Links − Nodes + 2. Why the distractors are wrong: A is off by one…

Analytical Techniques

Question

Which of the following is a valid way to calculate the cyclomatic complexity? 1 credit [K2]

Options

  • ANumber of decisions + 2
  • BNumber of enclosed regions - 1
  • CNumber of statements - 2
  • DLinks - Nodes + 2

How the community answered

(49 responses)
  • A
    4% (2)
  • B
    6% (3)
  • C
    2% (1)
  • D
    88% (43)

Explanation

Option D is correct because cyclomatic complexity is defined by McCabe's formula: M = E − N + 2P, where E = edges (links), N = nodes, and P = connected components (typically 1 for a single program), reducing to Links − Nodes + 2.

Why the distractors are wrong:

  • A is off by one - the correct decision-based formula is decisions + 1, not +2. Adding 2 instead of 1 is a common trap.
  • B inverts the region-based formula - the correct version is enclosed regions + 1 (each loop or branch adds a region). Subtracting 1 gives the wrong result.
  • C is entirely wrong - statement count has no role in cyclomatic complexity; it measures decision paths, not lines of code.

Memory tip: Think of the acronym ELNA - Edges Less Nodes, Add 2. Or remember that cyclomatic complexity always uses graph theory terms (nodes, edges/links), so any formula using "statements" is automatically a distractor.

Topics

#cyclomatic complexity#control flow graph#complexity metrics#links nodes

Community Discussion

No community discussion yet for this question.

Full CTAL-TTA_001 Practice