Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Prim’s and Kruskal’s Algorithm for MST

Both Prim’s and Kruskal’s algorithms are developed for discovering the minimum spanning tree of a graph. Both the algorithms are popular and follow different steps to solve the same kind of problem.

The prim’s algorithm selects the root vertex in the beginning and then traverses from vertex to vertex adjacently. On the other hand, Krushal’s algorithm helps in generating the minimum spanning tree, initiating from the smallest weighted edge.

What is Prim’s Algorithm?

Prim’s algorithm is popular as a greedy algorithm that helps in discovering the smallest spanning tree for a weighted undirected graph. That means, this algorithm tends to search the subgroup of the edges that can construct a tree, and the complete poundage of all the edges in the tree should be minimal.

What is the Kruskal Algorithm?

In the world of computer science, Kruskal’s Algorithm is used to discover the smallest spanning tree of a connected graph and the spanning forest of an undirected edge-weighted graph. Basically, it accepts a graph as input and discovers the subgroup of the edges of that graph.

Difference between Prims and Kruskal Algorithm

S.No. Prim’s Algorithm Kruskal’s Algorithm
1 This algorithm begins to construct the shortest spanning tree from any vertex in the graph. This algorithm begins to construct the shortest spanning tree from the vertex having the lowest weight in the graph.
2 To obtain the minimum distance, it traverses one node more than one time. It crosses one node only one time.
3 The time complexity of Prim’s algorithm is O(V2). The time complexity of Kruskal’s algorithm is O(E log V).
4 In Prim’s algorithm, all the graph elements must be connected. Kruskal’s algorithm may have disconnected graphs.
5 When it comes to dense graphs, the Prim’s algorithm runs faster. When it comes to sparse graphs, Kruskal’s algorithm runs faster.
6 It prefers list data structure. It prefers the heap data structure.

Keep learning and stay tuned to BYJU’S to get the latest updates on GATE Exam along with GATE Eligibility CriteriaGATE 2024GATE Admit CardGATE Application FormGATE SyllabusGATE CutoffGATE Previous Year Question Paper, and more.

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*