Data Structures & AlgorithmsVery hardProduct company OA

What is the size of a minimum vertex cover (a smallest set of vertices touching every edge) of the tree with edges 1–2, 1–3, 2–4, 2–5, 3–6, 6–7, 6–8, 5–9? (Tree DP: take[v] and skip[v].)

  1. A. 3
  2. B. 5
  3. C. 4
  4. D. 6

Correct answer: C. 4

skip[v] forces every child to be taken; take[v] lets each child choose. Leaves 4, 7, 8, 9 are skipped, forcing 2 (for 4), 6 (for 7, 8) and 5 (for 9). The edge 1–3 is not yet covered, so one of 1 or 3 is needed: e.g. {2, 5, 6, 3} or {1, 2, 5, 6}: size 4. Three vertices cannot cover the four pendant edges' parents plus edge 1–3.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic