The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+27 votes
5.4k views

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

  1. $6$ and $6$
  2. $8$ and $10$
  3. $9$ and $12$
  4. $4$ and $4$
asked in Compiler Design by Veteran (103k points)
edited by | 5.4k views
0
Notice - No node no node for '=' operator
+6

...............................

4 Answers

+40 votes
Best answer

A normal DAG construction will give $8$ nodes and $10$ edges as shown below.

Since, this question asks for minimum possible, we can assume algebraic simplification is allowed. So, $d = b + c, e = d - b$; can be simplified to $d = b + c$; $e = c$; Similarly, $e = d - b$; $a = e + b$; can be simplified to $a = d$. This gives the following DAG with $6$ nodes and $6$ edges.

https://cs.nyu.edu/~gottlieb/courses/2000s/2006-07-fall/compilers/lectures/lecture-14.html [working link]

answered by Veteran (359k points)
edited by
+1
Why is definition d added to node a? In 3rd statement c is getting redefined and hence the new value of c would be used for defining d. Hence a new node for d is created. What am I missing, Arjun Sir?
0
Sorry. It was a mistake. I have corrected it now.
+2
sir. the lnk is dead i need to study DAG . plz provide a gud link .
0
thanx arjun sir
0
@Arjun Sir, The link here is not working,have any alternative?
+2
Is DAG in syllabus?  but can questions of this type be expected anyone reply.... Isn't DAG used for optimisation?
0
is this in syllabus???
0
yes. it's in syllabus.
0
@Arjun Sir

In 2nd Figure am unable to find edge of  e = d-b; except this am understand ...I think 7 edges will be there?plzz look if you have time?
0
but code optimization is not, then how is it in syllabus? :(
0
what sort of question can we expect with dag because it involves code optimization techniques which are nt in syllabus?
0
@sushmita

I think it is intermediate code and DAG combination question and both of them are in syllabus..
+1
can we do it like this-

a=b+c

c=a+d

d=b+c

e=d-b

a=e+b

Now d is common subexpression so we need not compute it again-

Hence it will become-

a=b+c

c=a+d

e=a-b

a=e+b=a-b+b=a -----> redundant

Finally it becomes-

a=b+c

c=a+d

e=a-b

It will also require 6 nodes and 6 edges.
+20

isn't it right?

0
It is also correct!!!
+5

...........

0
Where is the assingment operator?
0
Had minimum not been asked, would be then go with 8 and 10 option?
+2 votes

Simplifying the given equations : 
 
d = b + c (given) e = d – b (given) => d = b + c and e = c 
 
e = d - b (given) a = e + b (given) => a = d 
 
2014-set3-44 
 
Thus, the given DAG has 6 nodes and 6 edges. 

answered by Loyal (8.5k points)
–2 votes
answer - B
answered by Loyal (9k points)
–2 votes
option B
answered by Active (2.6k points)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

41,063 questions
47,662 answers
147,321 comments
62,381 users