Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Prim’s and Kruskal’s Algorithm are used for finding the Minimum Spanning Tree (MST) of a given graph.

To apply these algorithms, the given graph must be weighted, connected and undirected.

To apply these algorithms, the given graph must be weighted, connected and undirected.

Concept-01:If all the edge weights are distinct, then both the algorithms are guaranteed to find the same MST.
Example-

Consider the following example-

Here, both the


algorithms on the above given graph produces the same MST as shown.

Concept-02: If all the edge weights are not distinct, then both the algorithms may not always produce the same
MST. However, cost of both the MSTs would always be same in both the cases.

Example-
Consider the following example-
Here, both the algorithms on the above given graph produces different MSTs as shown but the cost is same in both the
cases.

Concept-03:
Kruskal’s Algorithm is preferred when-

 The graph is sparse.

 There are less number of edges in the graph like E = O(V)

Prim’s Algorithm is preferred when-

 The graph is dense.


 There are large number of edges in the graph like E
Prim’s Algorithm Kruskal’s Algorithm
It starts to build the Minimum Spanning It starts to build the Minimum Spanning
Tree from any vertex in the graph. Tree from the vertex carrying minimum
weight in the graph.
In Prim’s algorithm, all the graph Kruskal’s algorithm may have
disconnected graphs.
elements must be connected.

Applications of prim’s algorithm are Applications of Kruskal algorithm are


Travelling Salesman Problem, Network LAN connection, TV Network etc.
for roads and Rail tracks connecting all
the cities etc.
Prim’s algorithm prefer list data Kruskal’s algorithm prefer heap data
structures. structures.

You might also like