0
3.6kviews
Explain cyclomatic complexity. How it is compared.

Subject: Software Engineering

Topic: Software design specification

Difficulty: High

1 Answer
1
87views

Cyclomatic complexity:-

Cyclomatic complexity is a source code complexity measurement that is being 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.

Cyclomatic complexity is used to gauge the overall intricacy of an application or specific functionality within it. The software metric quantitatively measures a program's logical strength based on existing decision paths in the source code. It is computed by using the control flow graph, where each node on the graph represents indivisible groups or commands within the program.

For example, an application consisting of zero decision points (IF, FOR, etc.) has an intricacy score of 1 because it contains a single path in the source code. If the program contains an IF statement consisting of one condition, the code would contain a total of two paths: TRUE or FALSE. The cyclomatic complexity algorithm is used to derive a measurable value based on the number of edges and nodes within the graph as well as the total count of connected components or exit nodes. It is represented as shown below:

Complexity (M) = Edges (E) – Nodes (N) + Exit Nodes (P)

Individual programs, subroutines, or methods always have one exit node, thus resulting in the value of P equaling one. This value remains consistent unless multiple applications with several exit points are to be assessed at the same time.

Lower the Program's cyclomatic complexity, lower the risk to modify and easier to understand. It can be represented using the below formula:

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

FlowGraph:

Cyclomatic complexity in Test Life Cycle

enter image description here

The Cyclomatic complexity is calculated using the above control flow diagram that shows seven nodes(shapes) and eight edges (lines), hence the cyclomatic complexity is 8 - 7 + 2 = 3

Please log in to add an answer.