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

i was calculating Cyclomatic Complexity of above pseudo code, and i came to conclusion with the short cut method that

M= (Decision Point) + 1

Where M is Cyclomatic Complexity

i Got answer 3

is it True?

JosEduSol
  • 5,268
  • 3
  • 23
  • 31
Ravi Mehta
  • 454
  • 1
  • 8
  • 20

2 Answers2

10

First, let identify every statement. Im using letters here, but it could 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 statement have two conditions/predicates/decision points (or whatever you call them), so i name them B and C.
  • Im going to use end while (G) as the exit point.

Now we can draw the Control Flow Graph (CFG):

CFG

Finally, compute the Cyclomatic Complexity (M) in three different ways:

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

  2. M = C + 1 = 3 + 1 = 4

  3. M = Regions(CFG) = 4

where:

  • E=number of edges

  • V=number of vertices

  • K=number of graph components

  • C=number of conditions/decision points

JosEduSol
  • 5,268
  • 3
  • 23
  • 31
3

As compare to above logic, @osEduSol mentioned is correct i.e.

M= (Decision Point) + 1

Where M is Cyclomatic Complexity

There are 3 decision point

i Got answer 4

Nagesh Pathrut
  • 139
  • 2
  • 10