← Back to All Algorithms

🌲 Prim's MST Algorithm

How It Works (Greedy)

  1. Start from any vertex, add to tree
  2. Find minimum weight edge connecting tree to non-tree vertex
  3. Add that edge and vertex to tree
  4. Repeat until all vertices are in tree

Key: Uses priority queue with key[v] = min edge weight to reach v

Click "Start" to find MST starting from A