Dark Mode

2,487 views

2 votes

Which one of the following is used to compute cyclomatic complexity ?

- The number of regions $-1$
- $E – N + 1$, where $E$ is the number of flow graph edges and $N$ is the number of flow graph nodes.
- $P – 1$, where $P$ is the number of predicate nodes in the flow graph $G$.
- $P + 1$, where $P$ is the number of predicate nodes in the flow graph $G$.

1 vote

Best answer

Cyclomatic complexity is a metric to measure logical complexity of a program.

- Cyclomatic complexity defines the number of independent paths in a program
- It gives an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once
- An independent path is any path through the program that introduces at least one new set of processing statements or a new condition.

Cyclomatic complexity is computed in one of three ways:

1. The number of regions of the flow graph

2. Cyclomatic complexity, V(G), for a flow graph, G, is defined as V(G) = E - N+ 2k where E is the number of flow graph edges, N is the number of flow graph nodes and k is the number of connected components or number of exit points.

3. V(G) = P+ 1 where P is the number of predicate (condition) nodes contained in the flow graph G.

Answer **(D)**