Question:

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 is represented internally as a Directed Acyclic Graph (DAG). The number of nodes in the DAG is \(\underline{\hspace{2cm}}\).

Show Hint

DAGs eliminate redundant computations by sharing common subexpressions.
Updated On: Jan 2, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 6

Solution and Explanation

Step 1: Identify common subexpressions.
The expression \( b + c \) appears twice and is computed only once in a DAG.

Step 2: Identify unique operations.
The distinct computations are:
\[ b + c, a + 1, d + 1, e + f \]

Step 3: Count operand nodes.
The variables involved are \( b, c, 1 \).

Step 4: Total node count.
- Operand nodes: \( b, c, 1 \)
- Operation nodes: \( b+c,\; +1,\; +1,\; + \)
Total nodes:
\[ 6 \] % Final Answer

Final Answer: \[ \boxed{6} \]

Was this answer helpful?
0
0

Top Questions on Intermediate code generation