GATE Computer ScienceVery hardGATE CS

A tree has vertices 0 to 9 with edges 0-1, 0-2, 1-3, 1-4, 2-5, 2-6, 4-7, 4-8, 6-9, and vertex weights w0 = 5, w1 = 4, w2 = 6, w3 = 3, w4 = 7, w5 = 2, w6 = 8, w7 = 1, w8 = 9, w9 = 4. What is the maximum total weight of an independent set (no two adjacent vertices chosen)?

  1. A. 26
  2. B. 28
  3. C. 27
  4. D. 30

Correct answer: B. 28

Use the tree DP in(v) = w(v) + Σ out(child) and out(v) = Σ max(in(child), out(child)). The optimum is {0, 3, 5, 6, 7, 8} with weight 5 + 3 + 2 + 8 + 1 + 9 = 28, which is also max(in(0), out(0)) at the root. No independent set exceeds this (checked by exhaustive search over all 1024 subsets).

More Algorithms questions

Exams that ask this topic