Data Structures & AlgorithmsHardGATE CS · ICPC regional
Weighted tree on vertices 0 to 8 with edges 0–1 (6), 1–2 (7), 0–3 (8), 0–4 (1), 0–5 (1), 5–6 (6), 2–7 (2), 4–8 (2). What is the largest possible sum of edge weights on a simple path between two vertices (the weighted diameter)?
- A. 5
- B. 15
- C. 33
- D. 23
Correct answer: D. 23
Two BFS/DFS sweeps on a tree give the heaviest path 23. Summing all weights, counting edges (5), or measuring from vertex 0 only (15) answer different questions.
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
- Array A = [25, 23, 7, 3, 1] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 5?
- Keys are inserted in the order 51 18 15 34 11 into an empty binary search tree. Then the key 18 (which has two children) is deleted by…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–C (1), B–D (1), B–E (1), B–G (1), C–D (1), D–F (1), D–G (1)…
- Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: A–C (7), B–D (9), A–D (6), A–E (5), B–F (6)…
- Points A(5,6), B(6,6), C(4,5), D(7,8), E(7,6) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- Dictionary D = {bdc, bds, cat, gce, lpb, nig, pgm, rmm, seg, tgm, tgs, tms} (all words have 3 letters). Starting from the word 'pmm', a…