Data Structures & AlgorithmsHardGATE CS · ICPC regional
A tree has vertices with weights in brackets: W[13], K[12], O[13], C[2], Z[8], F[8], P[5], Y[15]. The edges are W–K, W–O, O–C, C–Z, O–F, W–P, P–Y. A set of vertices is independent if no edge joins two of its members. What is the maximum total weight of an independent set?
- A. 43
- B. 44
- C. 48
- D. 47
Correct answer: C. 48
A tree DP (take a vertex and forfeit its children, or keep the children) gives 48. Greedily taking the heaviest vertex that conflicts with nothing gives only 44.
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
- Starting from the integer 13, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (12), 1→4 (1), 1→5 (8), 2→1 (10), 2→3 (2), 2→4 (7), 3→1 (1), 3→5…
- An undirected connected graph on the vertices D, L, R, T, V has the edges D–V, L–R, D–T, V–R, L–T, L–V, V–T, L–D. How many spanning trees…
- Each cell of a grid with 4 rows and 5 columns has an arrow: R = right, L = left, U = up, D = down. RUUUD RLDUL UDLDR RDDRU From a cell you…
- Starting from the integer 9, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- Two unmarked jugs hold 7 litres and 8 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…