To calculate the cyclomatic complexity of a code, I drew a control flow chart consisting of nodes and edges which helped me to calculate V (G) = E – N + 2
In my case E = 15 and N = 11. Resulting in a cyclomativ complexity of 6.
Now to confirm my answer I would like some help on finding linearly independent paths for the code blow:
int maxValue = m[0][0];
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if ( m[i][j] > maxValue )
{
maxValue = m[i][j];
}
}
}
cout << maxValue << endl;
int sum = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
sum = sum + m[i][j];
}
}
cout << sum << endl;
This should equal the result for my V (G), otherwise my calculation is wrong. Thank you for your help.
McCabe’s cyclomatic complexity gives an upper bound. Consider the following:
From a graph theory perspective, this has a cyclomatic complexity of three. However, since
do_specialis constant, there are only two independent paths through the code. The graph theory model doesn’t know that some paths are impossible. The number of possible paths through the graph is sometimes less than the cyclomatic complexity.