Question

Consider the basic block given below.

a = b + c
c = a + d
d = b + c
e = d - b
a = e + b

The minimum number of nodes and edges present in the DAG representation of the above basic block respectively are

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2014 answer key

Solution

Construct the Directed Acyclic Graph (DAG) for the basic block, identifying common subexpressions and algebraic cancellations.

Given the basic block statements:

  1. a = b + c

  2. c = a + d

  3. d = b + c

  4. e = d - b

  5. a = e + b

  6. Trace Expression Values:

    • Initial values of variables: b0,c0,d0b_0, c_0, d_0.
    • From statement 1: a1=b0+c0a_1 = b_0 + c_0.
    • From statement 2: c1=a1+d0=(b0+c0)+d0c_1 = a_1 + d_0 = (b_0 + c_0) + d_0.
    • From statement 3: d1=b0+c1=b0+((b0+c0)+d0)d_1 = b_0 + c_1 = b_0 + ((b_0 + c_0) + d_0).
    • From statement 4: e1=d1−b0=(b0+c1)−b0=c1e_1 = d_1 - b_0 = (b_0 + c_1) - b_0 = c_1.
      Thus e1e_1 evaluates identically to c1c_1 (pointing to the existing node for c1c_1).
    • From statement 5: a2=e1+b0=c1+b0=b0+c1=d1a_2 = e_1 + b_0 = c_1 + b_0 = b_0 + c_1 = d_1.
      Thus a2a_2 evaluates identically to d1d_1 (pointing to the existing node for d1d_1).
  7. DAG Structure:

    • Leaf nodes (3 nodes): b0,c0,d0b_0, c_0, d_0.
    • Interior operator nodes (3 nodes):
      • Node n1n_1 (+): left child b0b_0, right child c0c_0 (2 edges). Represents a1a_1.
      • Node n2n_2 (+): left child n1n_1, right child d0d_0 (2 edges). Represents c1c_1 and e1e_1.
      • Node n3n_3 (+): left child b0b_0, right child n2n_2 (2 edges). Represents d1d_1 and a2a_2.
  8. Counts:

    • Total nodes = 3 (leaves)+3 (interior)=6 nodes3\text{ (leaves)} + 3\text{ (interior)} = 6\text{ nodes}.
    • Total edges = 2+2+2=6 edges2 + 2 + 2 = 6\text{ edges}.

This matches option A (6 and 6).

Final answer

A

Common trap

Creating new DAG nodes for e = d - b and a = e + b without recognizing the algebraic identity cancellations.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2014 Computer Science and Information Technology (CS) Session 3
Question
44 of 65, printed as CS Q.34
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.