Data Structures & AlgorithmsHardGATE CS · ICPC regional
Weighted tree on vertices 0 to 7 with edges 0–1 (8), 0–2 (4), 0–3 (1), 1–4 (2), 1–5 (2), 5–6 (4), 1–7 (7). What is the largest possible sum of edge weights on a simple path between two vertices (the weighted diameter)?
- A. 28
- B. 4
- C. 19
- D. 15
Correct answer: C. 19
Two BFS/DFS sweeps on a tree give the heaviest path 19. Summing all weights, counting edges (4), 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
- Tree with vertices 0 to 6, root 0, edges 0–1, 0–2, 1–3, 3–4, 4–5, 2–6 (parent–child). Vertex weights (vertex:weight) 0:13, 1:5, 2:12…
- Distinct words ['baab', 'bcb', 'cbaa', 'ccba', 'bbaa', 'ab', 'aac'] are inserted into an empty trie (one node per character, shared…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–B (1), A–E (1), A–G (1), C–F (1), C–G (1), D–F (1), D–H (1)…
- Undirected graph on vertices A, B, C, D, E, F with weighted edges A–D (2), A–E (3), A–F (6), B–D (9), B–F (5), C–F (5), D–E (2), E–F (9)…
- Words ['b', 'c', 'babb', 'accc', 'aaa', 'c'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–D (16), A–E (3), B–C (6), B–E (16), C–D (2), C–E (14). What is…