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?

  1. A. 7 in the DAG, 10 in the tree
  2. B. 5 in the DAG, 10 in the tree
  3. C. 6 in the DAG, 11 in the tree
  4. 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

Exams that ask this topic