Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
A tree on vertices 1–11 has edges 2–1, 3–2, 4–1, 5–2, 6–3, 7–4, 8–6, 9–8, 10–8, 11–8. What is the size of a maximum independent set (no two chosen vertices adjacent)?
- A. 7
- B. 6
- C. 4
- D. 8
Correct answer: A. 7
Tree DP: in(u) = 1 + Σ out(child), out(u) = Σ max(in, out) of children; or greedily take every leaf and delete its parent. Both give 7. Taking the larger colour class of the bipartition (6) is not optimal here.
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 4 × 4 grid has rows 6 6 6 4 / 7 6 5 2 / 2 9 8 2 / 5 1 8 9. Moving only right or down from the top-left to the bottom-right cell, what is…
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: F→A (9), D→A (4), E→D (8), C→B…
- Floyd–Warshall runs on vertices 1–4 with directed edges 1→2 (1), 1→3 (5), 2→1 (1), 2→4 (8), 3→1 (3), 3→2 (9), 4→3 (2). After the…
- A tree on vertices 1–9 has edges 2–1, 3–1, 4–3, 5–2, 6–4, 7–6, 8–6, 9–8. What are its diameter and radius, and which vertex/vertices form…
- Five matrices have dimensions 12×10 , 10×4 , 4×6 , 6×6 , 6×8. What is the minimum number of scalar multiplications needed to compute their…
- An undirected graph has edges A–D, A–F, A–G, B–C, B–F, C–D, C–E, E–G, F–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…