Data Structures & AlgorithmsHardGATE CS · ICPC regional
Weighted tree on vertices 0 to 5 with edges 0–1 (3), 0–2 (1), 1–3 (2), 1–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. 21
- B. 12
- C. 19
- D. 4
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 (12) 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 7, root 0, edges 0–1, 1–2, 2–3, 0–4, 2–5, 2–6, 4–7 (parent–child). Vertex weights (vertex:weight) 0:8, 1:6, 2:7…
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–G, B–F, B–G, C–E, C–H, D–E. What is the size of a maximum…
- Weighted tree on vertices 0 to 7 with edges 0–1 (4), 0–2 (2), 0–3 (8), 0–4 (5), 1–5 (8), 0–6 (4), 0–7 (2). What is the largest possible…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 4 3 / 1 5 . Goal board: 1 2 3 / 4 5 . A move slides a…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–E (1), A–F (1), C–E (1), D–E (1), D–G (1), E–F (1), F–G (1)…
- Distinct keys [25, 10, 8, 14, 19] are inserted, in the order given by the sequence [19, 8, 14, 10, 25], into an empty binary search tree…