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?
3) Cyclomatic complexity V(G) = P +1 V (G) = 2 + 1 = 3 Where P is predicate nodes (node 1 and node 2) are predicate nodes because from these nodes only the decision of which path is to be followed is taken.
Cyclomatic complexity can be calculated by using control flow graphs or with respect to functions, modules, methods or classes within a software program. Independent path is defined as a path that has at least one edge which has not been traversed before in any other paths.
Cyclomatic complexity is a metric that indicates the possible number of paths inside a code artifact, e.g., a function, class, or whole program. Thomas J. McCabe Sr. developed this metric, first describing it in a 1976 paper.
It is a software metric that measures the logical complexity of the program code. It counts the number of decisions in the given program code. It measures the number of linearly independent paths through the program code.
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
end while
(G) as the exit point. Now we can draw the Control Flow Graph (CFG):
Finally, compute the Cyclomatic Complexity (M) in three different ways:
M = E-V+2*K = 9-7+2*1 = 4
M = C + 1 = 3 + 1 = 4
M = Regions(CFG) = 4
where:
E=number of edges
V=number of vertices
K=number of graph components
C=number of conditions/decision points
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With