Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): Y–K (11), S–K (2), Q–D (10), D–K (14), Y–S (3), Y–Q (29), Q–K (18), S–D (15), Q–S (7). A spanning tree is a set of n − 1 edges with no cycle. What is the weight of the second-smallest spanning tree, meaning the smallest total weight that is strictly larger than the minimum spanning tree weight?
- A. 27
- B. 22
- C. 33
- D. 26
Correct answer: D. 26
The minimum spanning tree weighs 22. Among the other spanning trees the smallest total is 26, obtained by one exchange of an MST edge for a non-tree edge. Adding the cheapest non-tree edge to the MST without the exchange gives 33.
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
- A tree has vertices with values in brackets: N[-2], J[9], M[1], R[0], H[9], G[6], S[-2]. The edges are N–J, J–M, N–R, M–H, N–G, J–S. A…
- A directed acyclic graph has the vertices A, H, N, Q, X, Z and the edges N→Z, H→Z, A→H, Q→H, Q→Z, Q→X. A topological order lists every…
- An undirected graph has the vertices A, B, D, P, R, Y and the edges P–D, P–B, P–R, D–A, D–Y, B–Y, A–R, R–Y. In how many ways can each…
- Each cell of a grid with 3 rows and 5 columns has an arrow: R = right, L = left, U = up, D = down. RURUR LRDLU RDDRD From a cell you may…
- On an 8×8 chessboard, rows and columns are numbered 0 to 7, and squares are written (row, column). A knight moves in the usual L-shape…
- Bellman–Ford is run from source X on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: F→I…