GATE CS 2021 Set 1 — Question 60
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.NAT+2 / -0MediumDAG for ExpressionsIntermediate Code GenerationCompiler Design
Compiler Design → Intermediate Code Generation → DAG for Expressions
Last updated
Question
Consider the following C code segment:In a compiler, this code segment is represented internally as a directed acyclic graph (DAG). The number of nodes in the DAG is __________.
a = b + c;
e = a + 1;
d = b + c;
f = d + 1;
g = e + f;
Correct answer
6 to 6
Solution
To find the number of nodes in the DAG, we identify unique sub-expressions and leaf nodes (variables/constants):
1.
a = b + c: Creates leaf nodes for b and c, and an internal node + with children (b, c). Node count: 3.2.
e = a + 1: Creates a leaf node for 1, and an internal node + with children (node_a, 1). Node count: .3.
d = b + c: The expression b + c is already represented by the node for a. No new nodes are created; d is just another label for that node.4.
f = d + 1: Since d is the same as a, d + 1 is the same as a + 1. No new nodes are created; f is another label for the node for e.5.
Summary of nodes:g = e + f: Since e and f refer to the same node, this is node_e + node_e. We create one new internal node + with both children pointing to node_e. Node count: .- Leaves:
b,c,1(3 nodes) - Internal (operations):
+(forb+c),+(fora+1),+(fore+f) (3 nodes)
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on Intermediate Code Generation
2026 Set 2 Q17In C runtime environment, which one of the following is stored in heap?2026 Set 2 Q19Consider the following three ANSI-C programs, P1, P2, and P3. P1 [code] P2 [code] **P3**…2026 Set 1 Q27Consider the following C statements: Which of the following options is/are correct? [figure]2026 Set 1 Q28Which of the following statements is/are true?2026 Set 2 Q35A lexical analyzer uses the following token definitions - - …