GATE Computer ScienceHardGATE CS (PYQ pattern)
A DAG is built for r = (p − q) * (p − q) + (q − p) * (p − q) − (p − q), with * commutative and − not commutative. How many interior (operator) nodes does it have?
- A. 6
- B. 4
- C. 5
- D. 9
Correct answer: A. 6
Interior nodes: p − q (all three occurrences share it), q − p (a different node, since − is not commutative), (p−q)*(p−q), (q−p)*(p−q), the + and the final −: 6. Wrongly merging q − p with p − q would also merge the two products, giving 4; the expression tree has 9 operators.
More Compiler Design questions
- For the grammar S → C C; C → c C | d (augmented with S′), the canonical LR(1) automaton is built and then the states with identical LR(0)…
- Using the backpatching scheme (each relation gives 'if r goto ' then 'goto ', no fall-through optimisation, numbering from 100), the code…
- For the nested-loop code 1: s = 0; 2: i = 0; 3: L1: if i >= n goto L5; 4: j = 0; 5: L2: if j >= i goto L4; 6: s = s + j; 7: j = j + 1; 8…
- For the grammar E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id, what is FOLLOW(T)?
- Which of the following about iterative data-flow analyses is/are true? I. Live-variable analysis is a backward problem whose meet operator…
- For the code 1: x = 0; 2: y = 1; 3: L1: if x > n goto L4; 4: if y > m goto L2; 5: y = y + x; 6: goto L3; 7: L2: x = x + 2; 8: L3: x = x +…