# Cyclometric complexity

Cyclomatic complexity count of the number of decisions in the source code. The code is complex if the number of decisions.  It is used to specify the complexity of code. It is calculated using the Control Flow Graph of the code which measures the number of linearly independent paths.

Code complexity calculation

It can be calculated using the formula :

C = E – N + 2P

Where,

P = number of disconnected components of the flow graph

E = number of edges (transfers of control)

N = number of nodes (a sequential group of statements)

### Why it is important?

1. Code complexity identified has to go through reviews and additional dynamic testing.
2. It also helps to identify the test cases.
3. It reduces the coupling of code.
4. Remove unnecessary/redundant code

### Steps to follows to determine code complexity

1. Identify nodes and edges from code and construct a graph
2. Identify all the independent paths from the graph
3. Calculate the code complexity using the formula mentioned above

### Use of Cyclomatic Complexity:

• It helps to identify the independent path executions which would be very helpful for Developers and Testers.
• It helps in identifying the uncovered path of the software.
• It helps in increasing the code coverage.
• It helps to evaluate the risks associated with software
• It ensures that every path of the software has been tested at least once.
• These metrics being used earlier in the program helps in reducing the risks.