Every program encompasses statements to execute in order to perform some task and other decision-making statements that decide, what statements need to be executed. These decision-making constructs change the flow of the program.
If we compare two programs of same size, the one with more decision-making statements will be more complex as the control of program jumps frequently.
McCabe, in 1976, proposed Cyclomatic Complexity Measure to quantify complexity of a 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 gotostatements.
Process to make flow control graph:
● Break program in smaller blocks, delimited by decision-making constructs.
● Create nodes representing each of these nodes.
● Connect nodes as follows:
○ If control can branch from block i to block j
○ Draw an arc
○ From exit node to entry node
○ Draw an arc.
To calculate Cyclomatic complexity of a program module, we use the formula –
V(G) = e – n + 2
Where
e is total number of edges
n is total number of nodes
The Cyclomatic complexity of the above module is
e = 10
n = 8
Cyclomatic Complexity = 10 – 8 + 2
= 4
According to P. Jorgensen, Cyclomatic Complexity of a module should not exceed 10.
Comments are closed.