Data Structures & AlgorithmsHardGATE CS · ICPC regional
Tree with vertices 0 to 8, root 0, edges 0–1, 1–2, 1–3, 1–4, 2–5, 2–6, 6–7, 5–8 (parent–child). Vertex weights (vertex:weight) 0:11, 1:10, 2:12, 3:12, 4:12, 5:15, 6:8, 7:14, 8:4. 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. 65
- D. 54
Correct answer: C. 65
Tree DP with take/skip states gives 65. Greedily taking the heaviest vertices first gives 64, 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
- Array [27, 21, 1, 3, 16, 28, 17] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…
- On an 8 × 8 chessboard with rows and columns numbered 0 to 7, a knight starts at (5, 7) and must reach (0, 5) (as (row, column)). A knight…
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (6), A–E (6), A–F (7), B–C (3), B–D (6), B–F (9), C–E (8), D–F (5)…
- Words ['dd', 'da', 'bb', 'bd', 'db', 'cc', 'aba'] (each may be used at most once). A chain is a sequence of these words in which the first…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–D (2), A–E (1), B–C (2), C–D (1), C–E (3), D–E (2). An edge is CRITICAL…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–D (2), B–C (1), B–D (6), B–E (3), C–E (1). Among all…