Algorithm


Prim's Algorithm:

  1. Initialize a set to keep track of vertices included in the Minimum Spanning Tree (MST).
  2. Start with an arbitrary vertex and add it to the MST set.
  3. While the MST set does not include all vertices:
    1. Find the edge with the smallest weight that connects a vertex in the MST set to a vertex outside the MST set.
    2. Add the selected edge and the vertex to the MST set.
  4. Repeat until all vertices are included in the MST set.

Example:

Prim's Algorithm Example

Fig. 1: Step-by-Step Process of Prim's Algorithm

Note: Prim's Algorithm is suitable for connected, undirected graphs and ensures a minimum spanning tree.