Cyclometric Complexity or structural complexity because it gives an internal view of code. This approach is used in software engineering to find no. of independent paths through the program. This provides us with the upper bond for the no. of tests that must be conducted to ensure that all statements have been executed at least once and every condition has been executed on its true and false side.
Complexity measures are defined in terms of independent paths that when taken in combination will generate every possible path. An independent path is any path through the program that introduces at least one new set of processing statements for a new condition.
How to calculate cyclometric complexity ?
- V(G) = e – n + 2 p
- No. of regions
- No. of independent paths
where,
- n – no. of nodes
- e – no. of edges
- p – no. of connected components
For Example:
Calculating the Cyclometric Complexity of the Above Example:
- V(G) = e – n + 2p = 9-5+2 = 5
- Regions = 5
- Independent Paths = ACF, ADCF, ABEF, ABEB, ABEA
Properties of Cyclometric Complexity
- V(G) >= 1
- V(G) is the maximum number of independent paths in the graph
- Inserting & deleting functional statement to Graph does not affect V(G).
- The graph has only one path if and only if V(G) = 1.
- Inserting a new row in the graph increases V(G) by 1.
- V(G) depends on the decision structure of the graph.
Cyclometric Complexity V(G) of flow graph G is equal to no. of predicate or decision nodes plus one.
V(G) = π + 1
The only restriction is that every predicate node should have only two outgoing edges that are true Condition & another for false condition. If there are more than two outgoing edges the structure is required to be changed in order to have only two outgoing edges. If it is not possible then this formula is not applicable.
For Example:
No. of Predicate Nodes = 4( Nodes with two outgoing edges)
So, V(G) = 5
Discover more from easytechnotes
Subscribe to get the latest posts sent to your email.