The best known complexity metric
Cyclomatic complexity does not measure the size of software in the same way as the other sizing techniques described. Cyclomatic complexity is a software metric developed by Thomas McCabe in 1976 and is used to indicate the complexity of a program. It directly measures the number of linearly independent paths through a program’s source code.
Cyclomatic complexity is computed using the control flow graph of the program: the nodes of the graph correspond to indivisible groups of commands of a program, and a directed edge connects two nodes if the second command might be executed immediately after the first command. Cyclomatic complexity may also be applied to individual functions, modules, methods or classes within a program.
Mathematically the cyclomatic complexity is as:
M = E − N + 2P
- E = the number of edges of the graph
- N = the number of nodes of the graph
- P = the number of connected components