Calculation of cyclic complexity for pseudocode

while(m<n)
  if(x>y) AND (a<b) then
    a=a+1
    y=y-1
  end if 
m=m+1
end while

i calculated Cyclomatic Complexity above the pseudo-code, and I came to the conclusion using the short cut method that

M = (decision point) + 1

Where M is cyclomatic complexity

i got an answer 3

It's true?

+4
source share
2 answers

First, let it identify each statement. Im using the letters here, but it can be numbers instead.

A    while(m<n)              
B,C    if(x>y) AND (a<b) then
D        a=a+1
E        y=y-1
       end if 
F      m=m+1
G    end while
  • Note that the second operator has two conditions / predicates / decision points (or whatever you call them), so I call them B and C.
  • I am going to use end while(G) as an exit point.

Now we can draw a control flow graph (CFG):

CFG

, Cyclomatic Complexity (M) :

  • M = E-V + 2 * K = 9-7 + 2 * 1 = 4

  • M = C + 1 = 3 + 1 = 4

  • M = (CFG) = 4

:

  • E =

  • V =

  • K =

  • C = /

+6

, @osEduSol , ..

M = ( ) + 1

M -

3

i 4

0

All Articles