GATE Computer ScienceHardGATE CS

The live ranges (inclusive of both end points, in instruction numbers) of ten variables are [1,8], [2,5], [3,9], [4,6], [7,12], [10,14], [11,13], [6,10], [9,15] and [12,16]. Two variables whose ranges share an instruction cannot share a register. What is the minimum number of registers needed so that no variable is spilled?

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

Correct answer: B. 5

Interval graphs are perfect, so the minimum number of registers equals the maximum number of simultaneously live ranges. At instruction 12 the ranges [7,12], [9,15], [10,14], [11,13] and [12,16] are all live: 5. No point has 6 live ranges.

More Compiler Design questions

Exams that ask this topic