Data Structures & AlgorithmsHardGATE CS · ICPC regional
Tree with vertices 0 to 9, root 0, edges 0–1, 1–2, 1–3, 1–4, 3–5, 1–6, 2–7, 5–8, 4–9 (parent–child). Vertex weights (vertex:weight) 0:16, 1:19, 2:4, 3:13, 4:4, 5:6, 6:17, 7:7, 8:4, 9: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. 55
- B. 46
- C. 33
- D. 71
Correct answer: D. 71
Tree DP with take/skip states gives 71. Greedily taking the heaviest vertices first gives 46, 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
- Points A(4,3), B(7,5), C(8,9), D(6,6), E(4,6) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- A trie keeps a counter at each node, and every word of the list W = ['bb', 'bba', 'aabc', 'ac', 'aba', 'bbc', 'aab', 'ac'] is inserted…
- Directed graph on vertices A, B, C, D, E, F with edges E→F, E→A, C→D, D→C, D→B, B→C, A→C, A→D, B→D (no weights). What is the number of…
- A binary tree with distinct letters has preorder CHEGDBFA and inorder HECFBADG. What is its postorder traversal (left, right, root)…
- Directed graph on vertices A, B, C, D, E, F, G with edges G→E, A→D, F→A, G→F, C→E, B→E, A→B, B→G, E→G, A→C (no weights). What is the…
- Coins of denominations [12, 11, 5, 3] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 34?…