Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

A tree has the vertices D, J, K, M, O, R, U, W, Z and the edges K–Z, K–M, Z–D, M–U, D–J, D–W, D–O, K–R. A centroid is a vertex whose removal leaves no connected component with more than n/2 vertices. Which vertex is the centroid?

  1. A. O
  2. B. W
  3. C. Z
  4. D. R

Correct answer: C. Z

Removing Z leaves components of at most 4 vertices, while every other vertex leaves a component bigger than n/2. The highest-degree vertex D is a common wrong guess.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic