Data Structures & AlgorithmsHardGATE CS · ICPC regional

Tree with vertices 0 to 7, root 0, edges 0–1, 1–2, 0–3, 3–4, 2–5, 5–6, 1–7 (parent–child). Vertex weights (vertex:weight) 0:10, 1:14, 2:10, 3:11, 4:16, 5:8, 6:14, 7:14. Choose a set of vertices with no two adjacent in the tree that maximises the total weight. What is that maximum total weight?

  1. A. 33
  2. B. 64
  3. C. 44
  4. D. 54

Correct answer: B. 64

Tree DP with take/skip states gives 64. Greedily taking the heaviest vertices first gives 44, and the minimum vertex cover weight 33 is the complement, not the answer.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic