GATE Computer ScienceHardGATE CS (PYQ pattern)
Vertices 0–10 of the tree with edges 0-1, 1-2, 1-3, 3-4, 3-5, 5-6, 0-7, 7-8, 2-9, 9-10 carry weights w = 4, 7, 3, 9, 5, 2, 8, 6, 5, 4, 10 respectively. What is the largest total weight of a set of vertices, no two of which are adjacent?
- A. 36
- B. 41
- C. 44
- D. 39
Correct answer: D. 39
Tree DP: inc[u] = w[u] + Σ exc[child], exc[u] = Σ max(inc, exc of children); the root value is 39, matching a brute force over all 2¹¹ subsets.
More Algorithms questions
- Five cities have symmetric distances d(0,1) = 9, d(0,2) = 14, d(0,3) = 23, d(0,4) = 17, d(1,2) = 11, d(1,3) = 19, d(1,4) = 26, d(2,3) = 8…
- The standard 2-approximation for Vertex Cover scans the edges in the order 0-1, 1-2, 2-3, 3-4, 4-5, 5-6, 1-4, 2-5 and, whenever an edge…
- Items 0.5, 0.7, 0.5, 0.2, 0.4, 0.2, 0.5, 0.1, 0.6 (in this order) are packed into bins of capacity 1 by Next-Fit, First-Fit and…
- Longest-Processing-Time-first scheduling puts jobs, in non-increasing order of length, on the currently least loaded machine. For jobs of…
- For the string s = abaababaabaab (13 characters), a number p (1 ≤ p ≤ 13) is called a period if s[i] = s[i + p] for every valid i (p = 13…
- Boyer–Moore majority vote (candidate c and counter k; if k = 0 take the current element as c with k = 1; else increment k when equal and…