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?
- A. 33
- B. 64
- C. 44
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Distinct keys [10, 21, 12, 26, 19] are inserted, in the order given by the sequence [12, 21, 19, 10, 26], into an empty binary search…
- A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [20, 17, 5, 11, 19, 20], where Mi has size p[i−1] × p[i]…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–E (3), A–F (5), B–D (1), B–E (2), C–F (20), D–E (17), D–F…
- Directed weighted graph on vertices A, B, C, D with edges (u→v, w): D→B (3); B→C (4); A→C (6); D→A (2); A→D (2); D→C (6); B→A (8); B→D…
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: E→D (1); F→D (5); F→C (1); B→E (5); F→A (4)…
- Coins of denominations [12, 9, 8, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 18?…