Prim's Algorithm

Prim’s Algorithm is a greedy algorithm used to find the Minimum Spanning Tree (MST) for a weighted undirected graph. A Minimum Spanning Tree is a subset of the edges that connects all the vertices with the minimum total edge weight, without forming any cycles.

How Prim’s Algorithm Works

  • Start with any node as the initial part of the MST.
  • Find the smallest edge that connects a new vertex to the MST.
  • Add that edge and vertex to the MST.
  • Repeat steps 2 and 3 until all vertices are included.