McCabe's Cyclomatic Complexity V(G) of a control flow graph can be calculated using several standard methods [6]:
V(G)=P+1, where P is the number of predicate (decision) nodes.
V(G)=E−N+2, where E is the number of edges and N is the number of nodes.
V(G)=R, where R is the number of bounded and unbounded regions in the planar graph representation.
### 1. Cyclomatic Complexity of Program-X
Program-X contains three decision statements:
while ((i < value) AND (result <= maxint))
Number of predicate nodes P=3.
V(X)=P+1=3+1=4 ### 2. Cyclomatic Complexity of Program-Y
From the control flow diagram for Program-Y:
Total number of nodes N=8
Total number of directed edges E=10
V(Y)=E−N+2=10−8+2=4 *(Alternatively, counting the regions in the graph: 3 enclosed regions +1 external region =4.)*
### 3. Cyclomatic Complexity of Program-Z
Program-Z is formed by connecting the exit of Program-X to the entry of Program-Y via a single directed edge:
NZ=NX+NY
EZ=EX+EY+1
V(Z)=EZ−NZ+2=(EX+EY+1)−(NX+NY)+2=(EX−NX+2)+(EY−NY+2)−1=V(X)+V(Y)−1=4+4−1=7 Thus, the cyclomatic complexities are 4, 4, 7, which corresponds to option (A).