Data Structures & AlgorithmsVery hardGATE CS
A tree on vertices 1–11 has edges 2–1, 3–1, 4–1, 5–3, 6–3, 7–6, 8–5, 9–6, 10–9, 11–9. 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
- Keys 88, 38, 16, 75, 87, 68, 51, 36, 82, 61 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- In how many different ways can 'catsanddogs' be split into a sequence of words from the dictionary {cat, cats, and, sand, dog, dogs, s}…
- The boolean expression T ^ T | T ^ F (T = true, F = false, & = AND, | = OR, ^ = XOR) can be fully parenthesised in 5 ways. In how many of…
- What is the edit distance (insert, delete, substitute; each cost 1) between MATRIX and STRATEGY?
- A B-tree has minimum degree t = 3 (every non-root node has between 2 and 5 keys) and height 3 (a root-only tree has height 0). What are…
- How many subsets of {1, 4, 8, 9, 10, 11, 12} have sum exactly 27?