89 89 votes 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 $6$ and $6$ $8$ and $10$ $9$ and $12$ $4$ and $4$ Compiler Design gatecse-2014-set3 compiler-design code-optimization directed-acyclic-graph normal + – go_editor 53.3k views answer comment Share Follow Print See all 6 Comments 6 6 Comments reply Show 3 previous comments Nitesh Singh 2 commented Jan 20, 2019 reply Follow flag Yeah it is in syllabus. Question can be asked from anywhere if it is even a little bit in syllabus. So leave recent out of syllabus topics carefully. 0 0 replyShare pritishc commented Oct 14, 2020 reply Follow flag It is in syllabus now, i.e for 2021 onwards. 8 8 replyShare princeit07 commented Oct 6, 2022 reply Follow flag The answer is 6,6 If it asks for minimal as we need to do the modification. The answer will be 8 and 10 if they ask for normal DAG without modifcation. 22 22 replyShare Please log in or register to add a comment.
Best answer 98 98 votes 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. Reference: https://cs.nyu.edu/~gottlieb/courses/2000s/2006-07-fall/compilers/lectures/lecture-14.html Correct Answer: $A$ Arjun answered Dec 23, 2014 • edited Apr 29, 2019 by Naveen Kumar 3 Arjun comment Share Follow See all 24 Comments 24 24 Comments reply Show 21 previous comments aashish1406 commented Jan 1, 2024 reply Follow flag @shefali1 in your written question is wrong bcoz in que a= b+c but you written it a=b+e 0 0 replyShare Ahbar commented Jan 23, 2024 reply Follow flag There is no such thing as “Normal DAG” and “minimal DAG” representation of a Basic Block, The substitution method that they have used to get the answer as (6,6) does not exist in any canonical texts, There is only one method to create DAGs for Basic Blocks and it is given in the book “Compilers by Aho, Lam, ,Sethi, Ullman Second Edition Page 533”, The document that you have linked is just a copy paste from this book. If they wanted us to use substitution then they should have mentioned that all the variables except the last one are temporary variables which are not live after the Block since thats the only case you can reduce statements in a three address basic block using operator associativity and commutative properties to maintain semantics but they haven’t mentioned any such thing. They can’t even formulate questions without ambiguity, I think they do it on purpose in order to introduce the chance factor for deciding ranks. Its a rotten system of evaluation. 6 6 replyShare Vivid_Vivek commented Apr 11 reply Follow flag Is this DAG is right ? 0 0 replyShare Please log in or register to add a comment.
48 48 votes 6,6 is the answer. Souvik33 answered Oct 17, 2022 Souvik33 comment Share Follow See all 6 Comments 6 6 Comments reply Show 3 previous comments Tejaswee_Bommaluleni commented Nov 3, 2025 reply Follow flag @ananya_23 Will it be sufficient to draw DAG for only a1? We have to draw for a0,c1,d1,e0 also right ! 2 2 replyShare Taniii commented Aug 27 reply Follow flag @Souvik33 how can you initially calculate b0+b0..? so we wont be able to derive c1,a0...??i feel this is wrong. Please Correct me, if i am missing something 0 0 replyShare Abhishek_Joshi commented Aug 31 reply Follow flag this approach is wrong.You can find it difficult to solve other problem with this approach. 0 0 replyShare Please log in or register to add a comment.
28 28 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)) Nitesh Singh 2 answered Jan 20, 2019 Nitesh Singh 2 comment Share Follow See all 4 Comments 4 4 Comments reply Lakshman Bhaiya commented Jan 28, 2020 reply Follow flag @Nitesh Singh 2 How you put the bracket? 0 0 replyShare Nitesh Singh 2 commented Jan 29, 2020 reply Follow flag Brackets are just to indicate "appropriate value has been substituted in place of the previous variable". 0 0 replyShare nisargdoshi commented Nov 9, 2020 reply Follow flag I found this super easy, can we use this for any questions of similar kind? 1 1 replyShare jiminpark commented Dec 30, 2021 reply Follow flag @Nitesh Singh 2 Sir, Do we only need to find the expression for the final variable value given in the basic block (i.e A here) ? Please tell ! 0 0 replyShare Please log in or register to add a comment.
3 3 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 Thus, the given DAG has 6 nodes and 6 edges. Regina Phalange answered Apr 1, 2017 Regina Phalange comment Share Follow 0 reply Please log in or register to add a comment.
1 1 vote A Surya013 answered Jul 15, 2025 Surya013 comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Reposting the answer by @princeit07 Sameer Bawane answered Jun 9 Sameer Bawane comment Share Follow 0 reply Please log in or register to add a comment.