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.