Cyclomatic complexity

Cyclomatic complexity is a software measurement metric which was developed by McCabe in 1976 to measure the complexity of source program. It measures quantitative number of linear independent paths through the program source code. It is calculated with the help of control flow graph or flow chart of the source code that measure the independent path of the project modules.

It is also called as code complexity.

It is process of evaluation of logical complexity of the source code or program

It represents behaviour of the system and all possible sequence of event (paths) in the execution.

Structure is modeled by control flow graph i.e. edge and node.

It is used in the context of the basis path testing method and the value computed for cyclomatic complexity defines the number of independent paths in the set of programs.

It provides upper bound for the number of tests that must be conducted to ensure that all statement has been executed at least once.

It is based on foundation of graph theory and computed with the help of:
CC = E – N + 2
Where,
CC = Cyclomatic Complexity
E = Number of edges
N = Number of nodes

Example -:
To calculate greater number among two numbers
1] Start
2] Enter two values (a, b)
3] Check condition for greater (if (a > b)
4] Print greater number (Print a)
5] Else
6] Print other number (Print b)
7] Stop

CC

From above diagram,
Total Number of Nodes = 06
Total Number of Edges = 06
Cyclomatic Complexity is as -:
CC = E – N + 2
= 6 – 6 + 2
= 2

We can verify by other way also
CC = R + 1
Where CC = Cyclomatic Complexity
R = Closed Region

Cyclomatic Complexity is as -:
CC = R + 1
= 1 + 1
= 2

This value indicates that the upper bound on the number of tests that must be designed and execute to guarantee coverage of all source code or program statements.

Leave a Reply