GATE Computer ScienceHardGATE CSE · UGC NET
The expression ((((a + b) + c) * ((a + b) + d)) - ((a + b) * ((a + b) + c))) is stored as a DAG with common subexpressions shared (no algebraic rewriting; + and * are NOT assumed commutative for sharing). How many internal (operator) nodes does the DAG have, compared with its expression tree?
- A. 7 in the DAG, 10 in the tree
- B. 5 in the DAG, 10 in the tree
- C. 6 in the DAG, 11 in the tree
- D. 6 in the DAG, 10 in the tree
Correct answer: D. 6 in the DAG, 10 in the tree
Distinct operator nodes: (+ v:a v:b); (+ (+ v:a v:b) v:c); (+ (+ v:a v:b) v:d); (* (+ (+ v:a v:b) v:c) (+ (+ v:a v:b) v:d)); (* (+ v:a v:b) (+ (+ v:a v:b) v:c)); (- (* (+ (+ v:a v:b) v:c) (+ (+ v:a v:b) v:d)) (* (+ v:a v:b) (+ (+ v:a v:b) v:c))) — 6 in all, against 10 operator occurrences in the tree.
More Compiler Design questions
- Control-flow graph: B1: a=1; b=2; c=a+b; then B2: d=c+b; if d<10 goto B4 (else B3); B3: c=d+a; b=c; goto B2; B4: print(c+a). Edges: B1→B2…
- Let L = { w ∈ {a,b} : the 4th symbol from the right end of w is 'a' }. The minimal DFA for L has how many states (including any dead/trap…
- Procedure P(x, y) { x = x + 1; y = x + y; } is called as P(a, a) with a = 3. What is a after the call under call-by-reference, and under…
- Grammar: S → L = R | R; L → R | id; R → L (augmented with S' → S). How many states do the LR(0) automaton and the canonical LR(1)…
- Grammar: S → a A d | b B d | a B e | b A e; A → c; B → c. How many states does the canonical LR(1) collection contain, how many does…
- For the standard expression grammar E → E + T | T; T → T F | F; F → ( E ) | id (augmented), how many states does the canonical LR(1)…