Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A tree has vertices with weights in brackets: U[11], E[3], J[12], L[9], K[11], B[6], G[1]. The edges are U–E, E–J, J–L, J–K, U–B, J–G. 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. 27
- B. 32
- C. 31
- D. 23
Correct answer: B. 32
A tree DP (take a vertex and forfeit its children, or keep the children) gives 32. Greedily taking the heaviest vertex that conflicts with nothing gives only 23.
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
- An undirected graph has the vertices F, H, I, K, N, U and the edges U–K, U–H, F–K, F–N, I–H, K–H. In how many ways can each vertex be…
- An undirected connected graph on the vertices F, G, I, Z has the edges Z–G, Z–I, F–Z, F–I, F–G, G–I. How many spanning trees does it have?…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {4, 5, 6} and s ≤ the pile size. The player who…
- A directed graph has the vertices E, H, L, M, Q, U and the arcs H→U, M→Q, U→H, U→Q, E→H, E→M, L→H. How many strongly connected components…
- A directed graph has the vertices C, I, L, R, U and the arcs I→U, I→C, I→L, R→I, R→U, R→C, R→L, U→C, C→I, C→L, L→U. Count the directed…
- Grid with 3 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.G G.G. .... Each step, which is a move…