GATE Computer ScienceHardGATE CSE

Using Sethi–Ullman numbering (a leaf that is a left operand needs 1 register, a leaf that is a right operand can be used from memory and needs 0; an internal node needs max(l,r) if l ≠ r, else l+1), what is the minimum number of registers needed to evaluate (((a + b) * (c - d)) / ((e + f) * (g - h))) without spilling?

  1. A. 2
  2. B. 4
  3. C. 3
  4. D. 5

Correct answer: C. 3

(a+b) and (c−d) each need 1, so each product needs 2; the two products have equal labels 2, hence the division needs 2+1 = 3.

More Compiler Design questions

Exams that ask this topic