Cyclomatic Complexity

Cyclomatic Complexity

Cyclomatic Complexity

  • Cyclomatic Complexity:

                              This approach is used to find the number of independent paths through a program.

                        An Independent Path is any path through the program that introduces at least one new set of processing statements or a new condition.

                        This provides us the upper bound for the number 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.


McCabe’s Cyclomatic Matrix ‘V (G)’ of a Graphic ‘G’ with ‘n’ Vertices (Nodes); ‘e’ Edges, and ‘P’ Connected Components is

V (G) = e – n + 2P

 V (G)’ denotes the Cyclomatic Complexity of Flow Graph ‘G’.

  • Method: – 1

 V (G) = e – n + 2P

 Where ‘e’ = Edges

            ‘n’ = Vertices (Nodes)

            ‘P’ = Connected Components

Three Alternative methods are available for the complexity calculations:


  • Method: – 2

Cyclomatic Complexity V (G) of a flow G is equal to the number of predicate (Decision) nodes plus one.

V (G) =  ∏ + 1

 Where ‘∏’ is the number of predicate nodes contained in the flow graph G.



  • Method: – 3

 Cyclomatic Complexity V (G) is equal to the number of regions of the flow graph.

(As shown below):

  • Method: – 4



 Find the Cyclomatic Complexity of the following Graph:




  • Halstead’s software science is a method of measuring the complexity of a program.
  • By allowing us to compare the inherent complexity of two programs, the software science metric can also be used to measure the productivity of the two programmers who produced those programs.
  • Halstead metric is applied to an existing piece of software and can be used to compare such things as the complexity of two different programs or the relative benefits of two programming languages.
  • In the planning stages of a project, however, we do not have a program therefore cannot use Halstead’s or any other code-based metrics to measure its inherent complexity.
  • Metrics like Halstead’s are called structural metrics because they depend on the structure of the software.
  • Instead, we need the predictive method to estimate the complexity of software before it has been developed, based on available information, such as the requirements. Function points are an example of this class of metrics.
  • Good Modularization is important in achieving any of the desired qualities but how we can determine whether one program is Modularized “better” than another.

For example 

a module length should not exceed 50 lines of code, or one page.” Such recommendations, however, are too simplistic: they measure the size of the module independently of the module’s logical organization.











Related Post

One thought on “Cyclomatic Complexity

Leave a Reply

Your email address will not be published. Required fields are marked *