GateAI
Cyclomatic Complexity

GATE CSE 2015 Set 3 · Q55

MCQ2 marksMedium

Time

Consider three software items: Program-XX, Control Flow Diagram of Program-YY and Control Flow Diagram of Program-ZZ as shown below The values of McCabe's Cyclomatic complexity of Program-XX, Program-YY, and Program-ZZ respectively are

GATE CSE 2015 Set 3 Q55 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) 4, 4, 7

Cyclomatic Complexity

McCabe's Cyclomatic Complexity V(G)V(G) of a control flow graph can be calculated using several standard methods [6]:

  1. V(G)=P+1V(G) = P + 1, where PP is the number of predicate (decision) nodes.

  2. V(G)=E−N+2V(G) = E - N + 2, where EE is the number of edges and NN is the number of nodes.

  3. V(G)=RV(G) = R, where RR is the number of bounded and unbounded regions in the planar graph representation.

### 1. Cyclomatic Complexity of Program-XX Program-XX contains three decision statements:

  • if (value < 0)

  • while ((i < value) AND (result <= maxint))

  • if (result <= maxint)

Number of predicate nodes P=3P = 3.

V(X)=P+1=3+1=4V(X) = P + 1 = 3 + 1 = 4

### 2. Cyclomatic Complexity of Program-YY From the control flow diagram for Program-YY:

  • Total number of nodes N=8N = 8

  • Total number of directed edges E=10E = 10

V(Y)=E−N+2=10−8+2=4V(Y) = E - N + 2 = 10 - 8 + 2 = 4

*(Alternatively, counting the regions in the graph: 3 enclosed regions +1+ 1 external region =4= 4.)*

### 3. Cyclomatic Complexity of Program-ZZ Program-ZZ is formed by connecting the exit of Program-XX to the entry of Program-YY via a single directed edge:

  • NZ=NX+NYN_Z = N_X + N_Y

  • EZ=EX+EY+1E_Z = E_X + E_Y + 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\begin{aligned} V(Z) &= E_Z - N_Z + 2 \\ &= (E_X + E_Y + 1) - (N_X + N_Y) + 2 \\ &= (E_X - N_X + 2) + (E_Y - N_Y + 2) - 1 \\ &= V(X) + V(Y) - 1 \\ &= 4 + 4 - 1 = 7 \end{aligned}

Thus, the cyclomatic complexities are 4, 4, 7, which corresponds to option (A).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Cyclomatic Complexity previous year question is Q55 of the GATE CSE 2015 Set 3 paper. Find more GATE CSE PYQs on Cyclomatic Complexity in Software Engineering, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 1 related Cyclomatic Complexity PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Cyclomatic Complexity in GATE CSE

GATE CSE 2015 Set 3 Q55 is the only Cyclomatic Complexity question in the GATE CSE papers so far.

How GATE tests Cyclomatic Complexity

More from GATE CSE 2015 Set 3

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2015 Set 3 · Q55 · MCQ

Consider three software items: Program-X, Control Flow Diagram of Program-Y and Control Flow Diagram of Program-Z as shown below The values of McCabe's Cyclomatic complexity of Program-X, Program-Y, and Program-Z respectively are

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.