• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
August 23, 2024 |7.3K Views

Prim's Algorithm for MST(with Code Walkthrough)

  Share  2 Likes
Description
Discussion

We have discussed Kruskal’s algorithm for Minimum Spanning Tree. Like Kruskal’s algorithm, Prim’s algorithm is also a Greedy algorithm. It starts with an empty spanning tree. The idea is to maintain two sets of vertices. The first set contains the vertices already included in the MST, the other set contains the vertices not yet included. At every step, it considers all the edges that connect the two sets, and picks the minimum weight edge from these edges. After picking the edge, it moves the other endpoint of the edge to the set containing MST.

Prim's Algorithm for MST(with Code Walkthrough : https://www.geeksforgeeks.org/prims-minimum-spanning-tree-mst-greedy-algo-5/