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?

  1. A. V
  2. B. L
  3. C. G
  4. 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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic