Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS
A connected undirected graph has the vertices N, R, U, W, Z and weighted edges (weights in brackets): W–R (7), R–N (1), U–R (16), U–Z (5), W–N (14), U–N (11), W–U (16), R–Z (12). What is the total weight of a minimum spanning tree?
- A. 25
- B. 58
- C. 24
- D. 36
Correct answer: C. 24
Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 24. A heaviest-first spanning tree gives 58, and a shortest-path tree rooted at W gives 36.
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 graph has the vertices C, D, P, R, T, W and the edges D–T, T–W, T–P, W–P, P–C, W–C, D–P, R–P, R–C. What is the minimum…
- A connected undirected graph has the vertices C, G, O, Q, T, U and the edges G–T, G–Q, G–U, T–Q, T–C, Q–U, Q–O, Q–C, O–C. Parallel edges…
- An undirected graph has the vertices C, E, H, I, M, N, O, R, U, Y and the edges H–R, H–E, H–N, H–M, C–O, C–R, C–E, C–N, C–M, C–Y, C–I…
- A tree has the vertices D, J, K, M, O, R, U, W, Z and the edges K–Z, K–M, Z–D, M–U, D–J, D–W, D–O, K–R. A centroid is a vertex whose…
- A tree has vertices with values in brackets: A[-2], U[8], Y[5], G[0], Z[-3], V[6], T[1], J[-2]. The edges are A–U, U–Y, Y–G, G–Z, A–V…
- A tree has vertices with values in brackets: O[1], Y[4], S[5], A[2], U[2], L[6]. The edges are O–Y, Y–S, Y–A, O–U, O–L. A path is any…