GATE Computer ScienceModerateGATE CS

In the expression a = (b + c) * (b + c) - d / (b + c), the numbers of operator (internal) nodes in the syntax tree for the right-hand side and in its optimised DAG are respectively:

  1. A. 3 and 6
  2. B. 5 and 6
  3. C. 4 and 7
  4. D. 6 and 4

Correct answer: D. 6 and 4

The tree has +, + and * for the first term, + and / for the second, and the final -: 6 operator nodes. The DAG shares the single node b + c, leaving +, *, / and -, i.e. 4 nodes. The option order is tree then DAG.

More Compiler Design questions

Exams that ask this topic