The Gateway to Computer Science Excellence

+55 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]

Correct Answer: $A$

+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?

+2

Is DAG in syllabus? but can questions of this type be expected anyone reply.... Isn't DAG used for optimisation?

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?

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

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..

I think it is intermediate code and DAG combination question and both of them are in syllabus..

+4

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.

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.

+4 votes

**Best approach of doing this question is "Go in reverse order". and it has asked for minimum so we can simplify wherever possible.**

A = (E+B)

((D-B)+B) = (D) Because both + , - has same precedence

(B+C)

(B+(A+D))

(B+((B+C)+D))

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.6k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.4k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.2k
- Non GATE 1.4k
- Others 1.5k
- Admissions 595
- Exam Queries 573
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

50,833 questions

57,709 answers

199,415 comments

107,602 users