Skip to content
Official PYQ · 2014

GATE CS 2014 Set 3 Q34 — Local Optimization

Explain with AI

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
View worked solution

Answer: A

To find the minimum number of nodes and edges in the Directed Acyclic Graph (DAG) representation, we construct the DAG step-by-step while applying algebraic simplifications:

  1. Initial Leaves: We start with three leaf nodes for the initial values of the variables: bb, cc, and dd.
    Total Nodes = 3, Edges = 0
  2. a = b + c: Create Node 1 (operator +) with children bb and cc. Label this node as aa.
    Total Nodes = 4, Edges = 2
  3. c = a + d: Create Node 2 (operator +) with children Node 1 (aa) and dd. Label this node as cc.
    Total Nodes = 5, Edges = 4
  4. d = b + c: Create Node 3 (operator +) with children bb and Node 2 (cc). Label this node as dd.
    Total Nodes = 6, Edges = 6
  5. e = d - b: Since d=b+cd = b + c (from Node 3), substituting this gives e=(b+c)−b=ce = (b + c) - b = c. Thus, ee is algebraically equivalent to the value at Node 2. No new node is created; we simply add the label ee to Node 2.
  6. a = e + b: Since ee is equivalent to Node 2 (which represents cc), we have a=c+b=b+ca = c + b = b + c. This is algebraically equivalent to Node 1. No new node is created; we simply move the label aa to Node 1.

Thus, the final DAG contains exactly 6 nodes (3 leaves and 3 interior operator nodes) and 6 edges.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Local Optimization questions