Data Structures & AlgorithmsHardGATE CS · ICPC regional
Weighted tree on vertices 0 to 5 with edges 0–1 (1), 0–2 (9), 2–3 (6), 2–4 (9), 2–5 (6). What is the largest possible sum of edge weights on a simple path between two vertices (the weighted diameter)?
- A. 18
- B. 31
- C. 19
- D. 3
Correct answer: C. 19
Two BFS/DFS sweeps on a tree give the heaviest path 19. Summing all weights, counting edges (3), or measuring from vertex 0 only (18) 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
- Tree with vertices 0 to 6, root 0, edges 0–1, 1–2, 1–3, 1–4, 2–5, 5–6 (parent–child). Vertex weights (vertex:weight) 0:18, 1:5, 2:11, 3:9…
- Array A = [7, 14, 10, 21, 3, 17, 9, 20, 26]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 19? (A trie with subtree counts answers…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–D (1), B–D (1), B–E (1), B–F (1), B–G (1), C–D (1), C–G (1), D–E…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (5), A–E (2), B–E (2), C–D (6), C–E (3), D–E (6). Among all…
- Bipartite graph with left side {A, B, C}, right side {D, E, F} and edges A–D, A–E, B–F, C–D, C–F. What is the size of a maximum matching…
- A binary trie of 6-bit numbers stores the set S = [12, 44, 27, 7, 63, 30, 48]. For the query x = 39, what is the maximum value of x XOR s…