Data Structures & AlgorithmsHardGATE CS · ICPC regional
Weighted tree on vertices 0 to 7 with edges 0–1 (9), 0–2 (2), 1–3 (4), 0–4 (3), 2–5 (3), 5–6 (2), 6–7 (7). What is the largest possible sum of edge weights on a simple path between two vertices (the weighted diameter)?
- A. 30
- B. 6
- C. 27
- D. 14
Correct answer: C. 27
Two BFS/DFS sweeps on a tree give the heaviest path 27. Summing all weights, counting edges (6), or measuring from vertex 0 only (14) 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
- Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: A–D (2), A–C (3), A–F (6), B–C (5), D–E (5)…
- Complete undirected graph on vertices A to E with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Strings a = "bcbbba" and b = "accc". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Words ['ca', 'aa', 'dc', 'ab', 'dad', 'aca', 'aac'] (each may be used at most once). A chain is a sequence of these words in which the…
- Directed graph on vertices A, B, C, D, E, F, G with edges C→A, E→A, E→G, G→C, G→F, F→C, C→G, C→B (no weights). What is the number of…
- On an 8 × 8 chessboard with rows and columns numbered 0 to 7, a knight starts at (4, 7) and must reach (1, 0) (as (row, column)). A knight…