Data Structures & AlgorithmsModerateGATE CS · ICPC regional
A connected undirected graph has the vertices D, E, O, P, W and weighted edges (weights in brackets): D–P (3), E–P (19), D–E (8), P–O (5), D–W (7), P–W (11), D–O (19), O–W (2). What is the total weight of a minimum spanning tree?
- A. 18
- B. 57
- C. 17
- D. 19
Correct answer: A. 18
Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 18. A heaviest-first spanning tree gives 57, and a shortest-path tree rooted at D gives 23.
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 bipartite graph has left side P1, P2, P3 and right side Q1, Q2, Q3, Q4, Q5, with edges P3–Q1, P1–Q2, P3–Q2, P3–Q4, P1–Q5, P2–Q4, P1–Q1…
- A grid has 4 rows and 3 columns with these values (top to bottom): 944 176 815 649 A path moves between side-adjacent cells (up, down…
- A tree has vertices with values in brackets: R[-3], G[6], I[7], U[-4], H[3], W[1], P[9], O[-3]. The edges are R–G, G–I, I–U, R–H, R–W…
- An undirected graph has the vertices A, G, Q, Z and the edges Z–A, Z–G, Q–A, Q–G. In how many ways can each vertex be given one of 3…
- A directed acyclic graph has the vertices E, N, O, S, U, V, Z and the edges Z→S, N→O, U→V, U→N, U→O, E→V, E→S. A topological order lists…
- An undirected graph on 6 vertices has the edges I–S, I–F, I–W, I–Q, I–K, S–F, S–K, F–K. How many simple paths (no repeated vertex) go from…