Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
A tree has the vertices C, I, N, P, T, U, X, Y, Z and the edges N–Z, N–Y, N–U, Y–I, I–X, N–C, Y–T, T–P. What is the minimum number of vertices needed so that every edge has at least one endpoint in the chosen set?
- A. 5
- B. 3
- C. 2
- D. 4
Correct answer: B. 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 4, and the number of non-leaf vertices gives 4.
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
- A tree has the vertices A, B, C, H, L, V, W and the edges C–W, W–H, H–B, B–A, C–L, A–V. A centroid is a vertex whose removal leaves no…
- Cities M, R, T, V, W are joined by roads with these travel costs: W–M 7, W–R 14, W–V 12, W–T 8, M–R 19, M–V 20, M–T 5, R–V 15, R–T 13, V–T…
- A directed acyclic graph has the vertices J, K, L, Q, R, S, X, Y and the directed edges S→R, S→Y, K→Y, L→K, R→Q, Y→X, K→X, J→Q, Y→J, J→X…
- Consider this recursive function: python def f(n): if n <= 0: return f(n - 1) if n % 2 == 0: f(n - 2) How many times is f called in total…
- Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→2 (4), 1→3 (8), 1→4 (4), 2→1 (5), 2→4 (2), 3→1 (6), 3→2 (5), 3→4…
- Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→2 (3), 1→4 (9), 2→3 (6), 2→4 (10), 3→1 (12), 3→2 (6), 4→1 (12), 4→2…