GATE CS 2021 Set 1 | Question 60

Compiler Design › Intermediate Code & Code Optimization · NAT · 2 marks · Answer: 6

  1. Question 60Compiler Designnat2 marks
    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 ______.

    Answer: 6

    Solution

    Leaves: b, c, and the constant 1 (3 nodes). b+c is a common subexpression shared by a and d (1 node). a+1 (= e, and d+1=f share the same value as they add 1 to the same node) and e+f add 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 →