36 Cyclomatic Complexity

McCabe’s Complexity Measures:

 

McCabe, in 1976, proposed Cyclomatic Complexity Measure to quantify complexity of given software. It is graph driven model that is based on decision-making constructs of program such as if-else, do-while, repeat-until, switch-case and goto statements. McCabe’s metrics are based on a control flow representation of the program. A program graph is used to depict control flow. Nodes represent processing tasks (one or more code statements), edges represent control flow between nodes.

 

 

Cyclomatic complexity can be defined as Set of independent paths through the graph (basis set)

 

V(G) = E – N + 2

 

E is the number of flow graph

edges N is the number of nodes

 

V(G) = P + 1

 

P is the number of predicate nodes

A predicate node is a node with two or more edges originating from it.

 

Summary

 

Cyclomatic complexity or structural complexity helps in identifying the upper bound on the maximum no of linearly independent paths that an algorithm can take. This helps in generating test cases.