0% found this document useful (0 votes)
67 views7 pages

Understanding Cyclomatic Complexity

Cyclomatic complexity is a metric for measuring source code complexity, which correlates with the likelihood of coding errors. It is calculated using a Control Flow Graph, with the formula Cyclomatic complexity = E - N + 2*P, where E is the number of edges, N is the number of nodes, and P is the number of exit points. A lower cyclomatic complexity indicates a lower risk of modification and easier code comprehension.

Uploaded by

k79aushik7540
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views7 pages

Understanding Cyclomatic Complexity

Cyclomatic complexity is a metric for measuring source code complexity, which correlates with the likelihood of coding errors. It is calculated using a Control Flow Graph, with the formula Cyclomatic complexity = E - N + 2*P, where E is the number of edges, N is the number of nodes, and P is the number of exit points. A lower cyclomatic complexity indicates a lower risk of modification and easier code comprehension.

Uploaded by

k79aushik7540
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Cyclomatic Complexity

• It is a source code complexity measurement.


• Correlated to a number of coding errors.
• It is calculated by developing a Control Flow Graph of the code that
measures the number of linearly-independent paths through a
program module.
• Lower the Program's cyclomatic complexity, lower the risk to modify
and easier to understand.
• Cyclomatic complexity = E - N + 2*P
• where,
• E = number of edges in the flow graph.
• N = number of nodes in the flow graph.
• P = number of nodes that have exit points
Example
IF A = 10 THEN
IF B > C THEN
A=B
ELSE
A=C
ENDIF
ENDIF
Print A
Print B
Print C
Flow Graph
• The Cyclomatic complexity of above graph is calculated using the
control flow diagram that shows seven nodes(shapes) and eight edges
(lines), hence the cyclomatic complexity is 8 - 7 + 2 = 3
Thank You

You might also like