Advertisement

Cyclomatic complexity calculator

Calculate control-flow complexity from edges, nodes and connected components, or find a missing graph count from a known complexity.

Calculator

Complexity
3.00000000
Edges
7.00000000
Nodes
6.00000000
Components
1.00000000

Advertisement

How this calculator works

Treat each module as a connected control-flow graph, with an entry and exit. Count the directed transitions as edges and basic blocks as nodes. Closing each exit back to its entry adds one edge per component; this gives the common software complexity convention. Counts alone cannot establish that the supplied graph is a valid control-flow graph.

Formula

M = E - N + 2P. For one connected module, P = 1 and M = E - N + 2.

Worked example

A module with 7 edges and 6 nodes has complexity 7 - 6 + 2 = 3. Two components with 8 edges and 8 nodes have complexity 4.

Advertisement

Frequently asked questions

Does this count all possible execution paths?

No. It measures a basis of independent paths. Loops can create infinitely many complete execution paths.

What is a node?

Use a consistent basic-block control-flow graph. Do not mix source lines, syntax tokens and graph nodes.

Can the answer be fractional?

No. Graph counts and complexity are integers. A fractional inferred component count means the supplied counts are inconsistent.

Sources

Advertisement