Data Structures & AlgorithmsHardGATE CS · TCS NQT
A connected undirected weighted graph on vertices 0 to 7 has the edges (u-v with weight): 0-1 (w=1), 0-5 (w=10), 1-2 (w=5), 1-3 (w=10), 1-7 (w=3), 2-4 (w=14), 2-5 (w=1), 2-7 (w=3), 3-4 (w=14), 3-6 (w=2), 4-5 (w=5), 5-6 (w=8), 5-7 (w=5). What is the total weight of a minimum spanning tree?
- A. 20
- B. 66
- C. 23
- D. 81
Correct answer: C. 23
Kruskal's algorithm takes edges in increasing weight and skips any edge that closes a cycle. Adding the n − 1 lightest edges ignores cycles, and taking edges in input order is not minimal.
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 connected undirected weighted graph on vertices 0 to 5 has the edges (u-v with weight): 0-1 (w=1), 0-2 (w=13), 0-3 (w=9), 0-4 (w=11)…
- A connected undirected weighted graph on vertices 0 to 7 has the edges (u-v with weight): 0-1 (w=3), 0-2 (w=10), 0-4 (w=12), 0-5 (w=13)…
- A connected undirected weighted graph on vertices 0 to 5 has the edges (u-v with weight): 0-1 (w=14), 0-2 (w=13), 0-3 (w=1), 0-4 (w=8)…
- A connected undirected weighted graph on vertices 0 to 4 has the edges (u-v with weight): 0-1 (w=5), 0-3 (w=3), 0-4 (w=14), 1-2 (w=10)…
- A connected undirected weighted graph on vertices 0 to 7 has the edges (u-v with weight): 0-1 (w=8), 1-2 (w=9), 1-3 (w=8), 1-4 (w=12), 1-5…
- A connected undirected weighted graph on vertices 0 to 7 has the edges (u-v with weight): 0-1 (w=15), 0-5 (w=12), 0-7 (w=7), 1-2 (w=2)…