GATE Computer ScienceHardGATE CS (PYQ pattern)

Vertices 0–10 of the tree with edges 0-1, 1-2, 1-3, 3-4, 3-5, 5-6, 0-7, 7-8, 2-9, 9-10 carry weights w = 4, 7, 3, 9, 5, 2, 8, 6, 5, 4, 10 respectively. What is the largest total weight of a set of vertices, no two of which are adjacent?

  1. A. 36
  2. B. 41
  3. C. 44
  4. D. 39

Correct answer: D. 39

Tree DP: inc[u] = w[u] + Σ exc[child], exc[u] = Σ max(inc, exc of children); the root value is 39, matching a brute force over all 2¹¹ subsets.

More Algorithms questions

Exams that ask this topic