McCabe Cyclomatic Complexity

To calculate the cyclic complexity of the code, I drew a control block diagram consisting of nodes and edges that helped me calculate V (G) = EN + 2 In my case, E = 15 and N = 11. As a result, the cyclomatic complexity is 6.

Now, to confirm my answer, I would like to help find linearly independent paths for hitting the code:

int maxValue = m[0][0];         
for (int i = 0; i < N; i++)         
{                       
   for (int j = 0; j < N; j++)          
   {                        
      if ( m[i][j] > maxValue )         
      {                     
         maxValue = m[i][j];            
      }                     
   }                        
}                   
cout << maxValue << endl;           
int sum = 0;                    
for (int i = 0; i < N; i++)         
{                       
   for (int j = 0; j < N; j++)          
   {                        
      sum = sum + m[i][j];          
   }                        
}                           
cout << sum << endl;  

This should equal the result for my V (G), otherwise my calculation is wrong. Thank you for your help.

+2
source share
2 answers

McCabe's cyclomatic complexity gives an upper bound. Consider the following:

void func (const bool do_special) {
    if (do_special) {
        do_something_special_at_the_start();
    }

    always_do_this_stuff_in_the_middle();

    if (do_special) {
        do_something_special_at_the_end();
}

. , do_special , . , . , .

+2

Hammen, , . - , , , . do_something _...(), . , P = 3, V (G) = E - N - 2 * P, E N . , :

void func (const bool do_special) {

   if (do_special) {
      /* do something at start */
   }
   :
   /* do something at middle */
   :
   if (do_speical) {
      /* do something at end */
   }
}

, !

0

All Articles