Prim's Algorithm

  • Explain how to implement Prim's algorithm.

A Greedy algorithm that grows an MST from a starting source vertex until it spans the entire graph:

  • Start with an empty minimum spanning tree T={}T = \{\}.
  • Pick a vertex vv (at random) and add it to TT.
  • Choose a vertex uu not in TT, such that the edge weight from a vertex in TT to uu is the least among all such edges.
  • Add uu to TT
  • Repeat the last two steps until (N1)(N – 1) edges were added.
Demo
Resources