Data Structures & AlgorithmsVery hardProduct-company placement
A tree on vertices 1–10 has edges 2–1, 3–2, 4–1, 5–2, 6–4, 7–3, 8–6, 9–7, 10–9. What is the size of a minimum DOMINATING set (every vertex is in the set or adjacent to one in it)?
- A. 5
- B. 4
- C. 3
- D. 2
Correct answer: C. 3
Greedy from the leaves up: a leaf's parent must be chosen (or the leaf dominated otherwise), then remove what it dominates and repeat; this gives 3. A minimum vertex cover (size 5) is a different problem.
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
- A simple undirected graph has 14 vertices and exactly 2 connected components. What is the maximum possible number of edges?
- How many structurally different binary trees with 7 nodes have height EXACTLY 5 (height = edges on the longest root-to-leaf path)?
- Keys 72, 29, 21, 18, 28, 16, 23, 33, 25, 67 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- DFS runs on the directed graph with adjacency lists A: BG; B: FG; C: AEFG; D: C; E: A; F: A; G: –, starting at A, scanning lists in the…
- A tree on vertices 1–8 has edges 2–1, 3–2, 4–2, 5–2, 6–2, 7–4, 8–3. What is the sum of the distances (in edges) over all unordered pairs…
- The weighted undirected graph A–B (1), A–C (3), A–D (5), B–D (3), B–E (6), C–D (3), D–E (6) has repeated weights. How many different…