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
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:
-
a = b + c -
c = a + d -
d = b + c -
e = d - b -
a = e + b -
Trace Expression Values:
- Initial values of variables: .
- From statement 1: .
- From statement 2: .
- From statement 3: .
- From statement 4: .
Thus evaluates identically to (pointing to the existing node for ). - From statement 5: .
Thus evaluates identically to (pointing to the existing node for ).
-
DAG Structure:
- Leaf nodes (3 nodes): .
- Interior operator nodes (3 nodes):
- Node (
+): left child , right child (2 edges). Represents . - Node (
+): left child , right child (2 edges). Represents and . - Node (
+): left child , right child (2 edges). Represents and .
- Node (
-
Counts:
- Total nodes = .
- Total edges = .
This matches option A (6 and 6).
A
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.