Use and Analysis On Cyclomatic Complexity in Software Development
Use and Analysis On Cyclomatic Complexity in Software Development
Abstract: Cyclomatic complexity is software metric used in software developments as White box testing and structural
testing. The purpose of the paper is to describe the Use and Analysis on Cyclomatic complexity in Software development
with an example. The Cyclomatic complexity is computed using the flow graph of the program: the nodes of the graph
correspond to one or more code statement and the edges connect two nodes. Based on the flow graph how to find
Cyclomatic complexity is described here.
Keywords: Cyclomatic Complexity, Flow graph, Predicate node, connected components, developers, testers.
1. INTRODUCTION
Cyclomatic complexity is software metric (measurement). It
was developed by Thomas J. McCabe, Sr. in 1976 and is used
to indicate the complexity of a program. It is a quantitative
measure of the complexity of programming instructions. It
directly measures the number of linearly independent paths
through a program’s source code. It is one of the metric based
on not program size but more on information/control flow.
www.ijcat.com 153
International Journal of Computer Applications Technology and Research
Volume 8–Issue 05, 153-156, 2019, ISSN:-2319–8656
The Cyclomatic Complexity is computed in one of five ways: V(G) = 3 + 1 = 4 (Condition nodes are 1,2 and 3
The number of regions of the flow graph nodes)
corresponds to the Cyclomatic complexity. Basis Set - A set of possible execution path of a
The Cyclomatic complexity, V(G), for a graph G is program
defined as V(G) = E – N + 2 1, 7
Where E is the number of flow graph edges and N is 1, 2, 6, 1, 7
the number of flow graph nodes. 1, 2, 3, 4, 5, 2, 6, 1, 7
The Cyclomatic complexity, V(G), for a graph G is 1, 2, 3, 5, 2, 6, 1, 7
defined as V(G) = E – N + 2P
Where E is the number of flow graph edges, N is the
number of flow graph nodes and P is connected 2. PROPERTIES OF CYCLOMATIC
components.
The Cyclomatic complexity, V(G), for a graph G is COMPLEXITY:
also defined as V(G) = P + 1
Where P is the number of predicate nodes contained Following are the properties of Cyclomatic complexity:
in the flow graph G. The predicate node is a node
that has of out degree two i.e. Binary node.
1. V (G) is the maximum number of independent paths
The Cyclomatic complexity, V (G), for a graph G is in the graph
also defined as total number of independent path of 2. V (G) >=1
flow graph. 3. G will have one path if V (G) = 1
4. Minimize complexity to 10
For Example:
2.1 How this metric is useful for software
i = 0;
testing?
n=4; //N-Number of nodes present in the graph
while (i<n-1) do Basis Path testing is one of White box technique and it
guarantees to execute at least one statement during testing. It
j = i + 1;
checks each linearly independent path through the program,
while (j<n) do which means number test cases, will be equivalent to the
if A[i]<A[j] then Cyclomatic complexity of the program.
Else
Statement 2
If (Condition 2)
Statement 3
Else
www.ijcat.com 154
International Journal of Computer Applications Technology and Research
Volume 8–Issue 05, 153-156, 2019, ISSN:-2319–8656
Cyclomatic complexity can be calculated manually if the Is the feature / program testable?
program is small. Automated tools need to be used if the Is the feature/ program understood by every one?
program is very complex as this involves more flow graphs. Is the feature / program reliable enough?
Based on complexity number, team can conclude on the
actions that need to be taken for measure. As a QA we can use this technique to identify the “level” of
our testing. It is a practice that if the result of Cyclomatic
Table 1 : Overview on the complexity number and complexity is more or a bigger number, we consider that piece
corresponding meaning of v (G): of functionality to be of complex nature and hence we
conclude as a tester; that the piece of code / functionality
requires an in-depth testing. On the other hand if the result of
1.4 Complexity 1.5 Meaning the Cyclomatic Complexity is a smaller number, we conclude
Number as QA that the functionality is of less complexity and decide
1.6 1-10 1.7 Structured and well the scope accordingly.
written code
High Testability
Cost and Effort is less Cyclomatic Complexity can prove to be
1.8 10-20 1.9 Complex Code very helpful in
Medium Testability
Cost and effort is Medium Helps developers and testers to determine
1.10 20-40 1.11 Very complex Code independent path executions
Low Testability Developers can assure that all the paths have been
Cost and Effort are high tested atleast once
1.12 >40 1.13 Not at all testable Helps us to focus more on the uncovered paths
Very high Cost and Effort Improve code coverage in Software Engineering
Evaluate the risk associated with the application or
program
3 TOOLS FOR CYCLOMATIC Using these metrics early in the cycle reduces more
risk of the program
COMPLEXITY CALCULATION:
www.ijcat.com 155
International Journal of Computer Applications Technology and Research
Volume 8–Issue 05, 153-156, 2019, ISSN:-2319–8656
5. CONCLUSION:
6. ACKNOWLEDGMENTS:
7. REFERENCES:
[1] https://www.guru99.com
www.ijcat.com 156