StatGardenREF. DESK
Calculators/Maths/Cyclomatic complexity
Maths

Cyclomatic complexity calculator

Complexity of a control-flow graph from its edge, node and connected-component counts.

What this calculator does

Cyclomatic complexity works out complexity of a control-flow graph from its edge, node and connected-component counts. Enter your own figures above and the answer updates as you type: nothing is fixed in the code, so the result reflects exactly the numbers you supply.

The formula this calculator evaluates is printed under the tool and explained below, so you can check the working by hand or reuse it in a spreadsheet.

The formula

FormulaM = E − N + 2P (E = edges, N = nodes, P = connected components, usually 1 for a single program)

The inputs explained

FieldWhat to enter
Edges (E)A number. Starts at 9.
Nodes (N)A number. Starts at 7.
Connected components (P)A number. Starts at 1.

Worked examples

Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.

How the answer changes with edges (e)

Every other input is held at the calculator’s starting values while edges (e) varies. Select any row to load that scenario into the calculator.

How the answer changes with edges (e)
Edges (E)Not a valid control-flow graph
4.5Edges, nodes and components do not correspond to a real graph (M must be at least 1)N/AN/A
6.752Low, simple to test2
94Low, simple to test4
13.59Low, simple to test9
1813Moderate13
2722High, hard to test thoroughly22