Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Tree with vertices 0 to 9, root 0, edges 0–1, 0–2, 2–3, 1–4, 3–5, 4–6, 5–7, 4–8, 8–9 (parent–child). Vertex weights (vertex:weight) 0:18, 1:4, 2:7, 3:9, 4:3, 5:16, 6:6, 7:8, 8:5, 9:19. Choose a set of vertices with no two adjacent in the tree that maximises the total weight. What is that maximum total weight?
- A. 60
- B. 52
- C. 35
- D. 59
Correct answer: A. 60
Tree DP with take/skip states gives 60. Greedily taking the heaviest vertices first gives 59, and the minimum vertex cover weight 35 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
- Keys [19, 23, 15, 12, 48, 41] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right, left–right…
- A binary tree with distinct letters has preorder FECBDGA and inorder CDGBEAF. What is its postorder traversal (left, right, root), written…
- Directed weighted graph on vertices A, B, C, D with edges D→C (-4); A→B (-1); D→B (6); C→B (2); A→D (-2); D→A (5); C→A (-2); B→A (6)…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–E (1), A–F (1), A–G (1), B–D (1), B–G (1), C–D (1), D–E (1), D–F…
- Directed acyclic graph on vertices A, B, C, D, E, F, G, H (edges go from earlier to later letters) with weights A→C (4), A→E (3), A→F (2)…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–G (1), B–F (1), B–G (1), C–E (1), C–F (1), C–G (1), D–E (1)…