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].)
- A. 3
- B. 5
- C. 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.
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
- In the tree with edges 1–2, 1–3, 2–4, 2–5, 3–6, 5–7, the rerooting technique computes S(v) = sum of distances from v to every other node…
- Each node of this binary tree holds a value; how many DOWNWARD paths (starting at any node, moving only to children, ending at any node)…
- Weighted undirected graph: A–B 1, B–C 2, C–D 3, D–A 4, A–C 5, B–D 6. The MST is unique. What is the weight of the SECOND-best spanning…
- Word ladder: change one letter at a time, every intermediate word must be in the dictionary {cold, cord, card, ward, warm, word, worm…
- In this grid, how many islands of 1s are there with 4-directional connectivity, and how many with 8-directional (diagonals also connect)?…
- What is the maximum path sum in this binary tree, where a path joins any two nodes along parent–child links and need not pass through the…