Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
A connected undirected graph has the vertices B, F, K, N, U, W and weighted edges (weights in brackets): F–U (13), F–N (4), N–U (17), B–W (6), K–B (19), K–N (11), W–U (16), K–F (17), B–F (16), K–U (10). What is the total weight of a minimum spanning tree?
- A. 48
- B. 44
- C. 47
- D. 82
Correct answer: C. 47
Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 47. A heaviest-first spanning tree gives 82, and a shortest-path tree rooted at K gives 50.
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
- 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…
- 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…