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?

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic