Consider the following pseudo-code: If (A > B) and (C > D) then A = A + 1 B =…
20072012
Consider the following pseudo-code:
If (A > B) and (C > D) then
A = A + 1
B = B + 1
EndifThe cyclomatic complexity of the pseudo-code is
Answer: B. 3 — Cyclomatic complexity for structured code can be counted as: number of predicate/decision conditions + 1. The IF statement contains a compound condition: (A >…
- A.
2
- B.
3
- C.
4
- D.
5
Attempted by 90 students.
Show answer & explanation
Correct answer: B
Cyclomatic complexity for structured code can be counted as:
number of predicate/decision conditions + 1.
The IF statement contains a compound condition:
(A > B) AND (C > D)
This has two atomic predicate conditions:
1. A > B
2. C > D
Because of short-circuit evaluation of AND, the linearly independent paths are:
1. A <= B, so the body is not executed.
2. A > B but C <= D, so the body is not executed.
3. A > B and C > D, so the body is executed.
Therefore, cyclomatic complexity = 2 + 1 = 3.