If we use Prim's Algorithm instead of Kruskal's Algorithm to construct the…

2023

If we use Prim's Algorithm instead of Kruskal's Algorithm to construct the Minimum Spanning Tree (MST) of a graph in which all edge weights are distinct, then

  1. A.

    we will get a different spanning tree.

  2. B.

    we will get the same spanning tree.

  3. C.

    the spanning tree will have fewer edges.

  4. D.

    the spanning tree will not cover all vertices.

Attempted by 5 students.

Show answer & explanation

Correct answer: B

The Minimum Spanning Tree (MST) of a connected, weighted graph is the spanning tree with the smallest possible total edge weight. The Cut Property states that for any partition (cut) of the graph's vertices into two non-empty sets, the minimum-weight edge crossing that cut must belong to every MST. When all edge weights in the graph are distinct, there is exactly one minimum-weight edge across each cut - so the Cut Property pins down a single edge at every step, meaning the graph has exactly one possible MST.

Prim's Algorithm and Kruskal's Algorithm are both correct MST algorithms, but they explore the graph differently: Prim's grows a single tree outward from a starting vertex, repeatedly adding the cheapest edge that connects the current tree to a new vertex, while Kruskal's looks at all edges globally in increasing order of weight and adds an edge whenever it does not create a cycle. Both strategies are proven to always output a valid MST. Since this graph's edge weights are all distinct, its MST is unique - so no matter which of the two algorithms is used, the resulting spanning tree must be exactly the same one.

This can be checked by considering what happens when some edge weights are equal: with tied weights, Prim's and Kruskal's can break the tie differently (say, by vertex order versus edge-list order) and end up building two different, equally minimal spanning trees. That divergence disappears exactly when distinct edge weights remove every tie - confirming that it is the graph's unique weights, not any special property of either algorithm, that forces the same result.

Explore the full course: Coding For Placement