Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
A tree has the vertices A, D, E, G, I, L, P, V, W and the edges L–G, L–W, W–P, W–A, A–E, P–D, P–I, L–V. A centroid is a vertex whose removal leaves no connected component with more than n/2 vertices. Which vertex is the centroid?
- A. V
- B. L
- C. G
- D. W
Correct answer: D. W
Removing W leaves components of at most 3 vertices, while every other vertex leaves a component bigger than n/2. The highest-degree vertex L is a common wrong guess.
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 directed acyclic graph has the vertices C, G, K, P, W, X, Z and the arcs Z→X, Z→G, Z→K, C→W, C→K, P→X, P→K, X→W, W→K, G→K. Two players…
- An undirected graph has the vertices H, J, K, N, P, Q, R and the edges K–R, K–P, Q–J, N–R, P–R, N–J, P–J, K–J, Q–R, H–J. How many simple…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 3} and s ≤ the pile size. The player who…
- A directed graph has the vertices B, H, L, Q, R, T, U, Z and the arcs B→L, B→H, B→R, B→Q, L→B, L→Z, L→H, Z→B, Z→L, Z→T, H→L, H→U, R→B…
- The directed acyclic graph has the vertices A, I, L, P, Q, W and the arcs W→P, I→A, W→I, L→I, Q→A, L→W, L→Q, L→A. How many distinct…
- An undirected graph has the vertices B, G, S, T, Y and the edges S–B, G–S, S–Y, S–T, B–T, G–Y, B–Y. What is the minimum number of edges…