GATE Computer ScienceVery hardGATE CS

A heap holds objects A to J. Roots point to A and E. Pointers: A→B, B→C, B→D, C→B, D→F, E→F, E→I, G→H, H→G, H→J. The root pointer to A is now removed. Reference counting (cascading decrements, no cycle detection) reclaims x objects at that moment, and a complete tracing (mark-sweep) collection run right afterwards would reclaim y objects in total, including any garbage that existed before. What is (x, y)?

  1. A. (4, 7)
  2. B. (1, 4)
  3. C. (1, 7)
  4. D. (1, 6)

Correct answer: C. (1, 7)

Removing the root count frees A, which decrements B from 2 to 1 (C still points to it), so the B–C cycle and D survive: x = 1. Tracing from the only root E marks E, F and I; everything else is unreachable: A, B, C, D, and the earlier garbage G, H, J, so y = 7.

More Compiler Design questions

Exams that ask this topic