Describe cyclomatic complexity with example.

Cyclomatic complexity is a software metric that measure the logical strength of the program. It was developed by Thomas J. McCabe. Cyclomatic complexity is calculated by using the control flow graph of the program. In the flow graph, nodes are represented by circle. Areas bounded by edges and nodes are called regions. When counting regions, we also include the area outside the graph as a region.


Complexity is computed in one of three ways:

The total number of regions of the flow graph.

By using the formula defined as:

V(G) = E - N + 2

Cyclomatic complexity, V(G), for a flow graph, G, is also defined as

V(G) = P + 1 ,where P is the number of predicate nodes contained in the flow graph G.

Note: Nodes that contain a condition is called a predicate node and is characterized by two or more edges originating from it.

0 comments:

Feel free to contact the admin for any suggestions and help.