Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A tree has the vertices B, E, K, L, N, P, Y, Z and the edges N–E, N–B, E–L, N–K, E–Z, L–P, N–Y. What is the minimum number of vertices needed so that every edge has at least one endpoint in the chosen set?
- A. 5
- B. 2
- C. 3
- D. 4
Correct answer: C. 3
Minimum vertex cover on a tree is computed by a DP over children (taking the parent or all children). It is 3 here. Repeatedly picking the highest-degree vertex gives 3, and the number of non-leaf vertices gives 3.
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, I, N, P, X, Y and the edges F–X, F–P, P–Y, P–X, I–Y, F–I, F–Y, F–N, N–I, I–X. What is the minimum…
- A directed graph has the vertices A, H, R, U, V, Y and the arcs V→A, A→H, A→R, U→R, H→R, Y→R, R→A, R→U, R→H. How many strongly connected…
- A directed graph has the vertices A, D, E, I, U and the arcs E→A, E→I, A→E, A→D, D→E, D→I, D→U, I→A, U→E, U→A, U→D. Count the directed…
- An undirected graph has the vertices A, G, N, O, S and the edges O–N, G–S, S–O, S–A, A–N, A–O, S–N. How many simple cycles does it contain…
- A bipartite graph has left side P1, P2, P3 and right side Q1, Q2, Q3, Q4, Q5, with edges P2–Q2, P3–Q1, P2–Q1, P1–Q5, P1–Q4, P1–Q2. What is…
- An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): B–H (11), B–I (7), C–H (30), E–I (16), B–C…