GATE CS 2021 Set 1 | Question 60
Compiler Design › Intermediate Code & Code Optimization · NAT · 2 marks · Answer: 6
- Question 60Compiler Designnat2 marksConsider 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;Answer: 6
Solution
Leaves:b,c, and the constant1(3 nodes).b+cis a common subexpression shared byaandd(1 node).a+1(=e, andd+1=fshare the same value as they add 1 to the same node) ande+fadd internal nodes, for a total of 6 distinct nodes.
More GATE PYQ on Intermediate Code & Code Optimization
All GATE CS Compiler Design PYQ →Attempt GATE CS 2021 Set 1 in real GATE exam mode
Full paper with a timer, the GATE interface and a topic-wise analysis — free.
Create free account →