I have a general question pertaining to Cyclomatic Complexity. Please have a look at the attached source code:
private void downShift(int index)
{
// index of "child", which will be either index * 2 or index * 2 + 1
int childIndex;
// temp storage for item at index where shifting begins
Comparable temp = theItems[index];
// shift items, as needed
while (index * 2 <= theSize)
{
// set childIndex to "left" child
childIndex = index * 2;
// move to "right" child if "right" child < "left" child
if (childIndex != theSize && theItems[childIndex + 1].compareTo(theItems[childIndex]) < 0)
childIndex++;
if (theItems[childIndex].compareTo(temp) < 0)
{
// shift "child" down if child < temp
theItems[index] = theItems[childIndex];
}
else
{
// shifting complete
break;
}
// increment index
index = childIndex;
}
// position item that was originally at index where shifting began
theItems[index] = temp;
}
From the above code, I drew out a flow graph as illustrated here:
and I counted out the number of nodes to be 10, and the number of edges to be 10 as well. Using the following formula, V(G) = E - N + 2P, I calculated 3 to be the cyclomatic complexity ( or V(G)).
Is my calculation correct? Thanks!