GATE 2021 CS – Question 60
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 ______.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 6
Explanation
Leaves: b, c, 1 (3 nodes). Internal nodes: b+c (shared by a and d), (b+c)+1 (shared by e and f), and g = e+f. Total = 3 + 3 = 6.