GATE Computer ScienceHardGATE CS (PYQ pattern)

Sethi–Ullman labelling (a leaf is 1 if it is a left child and 0 if it is a right child, since a right operand may come from memory; an interior node gets max(l1, l2) if l1 ≠ l2, else l1 + 1) gives the number of registers needed without spilling. Which expression needs exactly 3 registers?

  1. A. a + (b + (c + (d + e)))
  2. B. (a + (b * c)) − (d * (e + f))
  3. C. ((a − b) + c) * ((d + e) − (f + g))
  4. D. (a + b) * (c − (d + (e * f)))

Correct answer: B. (a + (b * c)) − (d * (e + f))

(a + (b*c)): a = 1, b*c = 1 → 2. d * (e + f): d = 1, e + f = 1 → 2. Equal labels → 3. The right-deep chain a + (b + (c + (d + e))) is 2 at every level (each inner sum is a right child labelled 1 against a left leaf 1, then 2 against a leaf 1). ((a−b)+c) = 1 and (d+e) − (f+g) = 2 give 2. (a+b) = 1 and c − (…) = 2 give 2.

More Compiler Design questions

Exams that ask this topic