GateAI
Data Flow Analyses

GATE CSE 2021 Set 1 · Q50

NAT2 marksMedium

Time

Consider the following C code segment:a = b + c; e = a + 1; d = b + c; f = d + 1; g = e + f;In a compiler, this code segment is represented internally as a directed acyclic graph (DAG). The number of nodes in the DAG is ________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 6

Data Flow Analyses

To construct the Directed Acyclic Graph (DAG) for the given basic block, we identify unique subexpressions:

  1. a = b + c:

    • Leaf nodes: b (Node 1) and c (Node 2)

    • Operator node: + with children b and c (Node 3, labeled a)

  2. e = a + 1:

    • Leaf node: 1 (Node 4)

    • Operator node: + with children Node 3 (a) and Node 4 (1) (Node 5, labeled e)

  3. d = b + c:

    • Common subexpression: b + c is already computed at Node 3. Thus, Node 3 is also labeled with d.

  4. f = d + 1:

    • Since d refers to Node 3 and 1 refers to Node 4, d + 1 is identical to a + 1, which is already represented by Node 5. Thus, Node 5 is also labeled with f.

  5. g = e + f:

    • Since e and f are both associated with Node 5, this is + applied with both left and right children being Node 5 (Node 6, labeled g).

Listing all nodes in the DAG:

  • Leaf nodes (3):b, c, 1

  • Internal/operator nodes (3):

    • + (labeled a, d)

    • + (labeled e, f)

    • + (labeled g)

Total number of nodes in the DAG = 3+3=3 + 3 = 6.

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 Data Flow Analyses previous year question is Q50 of the GATE CSE 2021 Set 1 paper. Find more GATE CSE PYQs on Data Flow Analyses in Compiler Design, 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 5 related Data Flow Analyses 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.

Data Flow Analyses in GATE CSE

Data Flow Analyses has 8 GATE CSE PYQs across 8 papers from 2014 to 2026. This is the only 2-mark NAT question among them, and it is the only one in GATE CSE 2021 Set 1.

How GATE tests Data Flow Analyses

More from GATE CSE 2021 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2021 Set 1 · Q50 · NAT

Consider the following C code segment: a = b + c; e = a + 1; d = b + c; f = d + 1; g = e + f; In a compiler, this code segment is represented internally as a directed acyclic graph (DAG). The number of nodes in the DAG is …

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.