Monday, September 15, 2014

Cyclomatic Complexity Defined

Cyclomatic complexity was developed by Thomas J. McCabe Sr in 1976, it is a software metric or a unit of measurement in programs primarily used in white-box testing. It is best defined as a measure of the logical complexity or intricacy of an algorithm. It is used to gauge or determine the complexity of an application or its specific functions. Cyclomatic complexity quantitatively determines the programs logical strength based on existing decision paths within the source code. The control flow graph of the program is computed using Cyclomatic complexity.

Using Cyclomatic Complexity on Your Software

Cyclomatic complexity aids in limiting standard intricacies during the development process of any program by splitting it into easier to manage or smaller components. Level 10 and below programs are considered to be within the acceptable range of cyclomatic complexity. This particular measurement can be used to easily identify problem areas while the program is at the source code level.

The cyclomatic complexity of a portion of a source code is the count of the number of independent paths throughout the program. For example, if the source code of a program contained no decision points like IF and FOR statements, the complexity or measurement would be 1 since there is only a single course throughout that section. However, if the code has a single IF statement then there would be 2 paths throughout the code. One path would be the noted as TRUE and the other would be FALSE. The algorithm or formular for the measure of cyclomatic complexity can be derived based on the number of edges and nodes on the control flow graph. 

It is best represented with the following equation:

M = E – N + P

Where:
M is the Complexity
E refers to the value of Edges
N refers to the value of Nodes
P refers to the value of Exit Nodes


Cyclomaticcomplexity aids program developers to determine the independent path executions and base line unit tests that they need to confirm. By using this, programmers can be sure that all program paths have been tested at least once and will greatly save time and effort during debugging of a program.