Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
A tree on vertices 1–11 has edges 2–1, 3–2, 4–2, 5–3, 6–3, 7–4, 8–6, 9–7, 10–7, 11–8. What is the size of a maximum independent set (no two chosen vertices adjacent)?
- A. 6
- B. 4
- C. 7
- D. 8
Correct answer: C. 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
- All suffixes of the string 'level' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?
- A DAG on vertices A–G has edges A→D, A→F, C→D, E→C, F→B, F→D, G→A, G→F. What order does Kahn's algorithm with a FIFO queue (initial zero…
- What is the edit distance (insert, delete, substitute; each cost 1) between DIAMETER and INTERVAL?
- Prim's algorithm starts at F on the weighted undirected graph A–B (18), A–F (15), B–E (26), B–F (23), B–G (21), C–D (9), C–E (16), D–E…
- A rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 1, 2, 5, 14, 16, 22, 24, 25. What is…
- An undirected graph has edges A–B, A–C, A–D, B–F, B–G, C–E, D–F, E–F, F–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…