← Back to All Algorithms
🌲 Prim's MST Algorithm
How It Works (Greedy)
Start from any vertex, add to tree
Find minimum weight edge connecting tree to non-tree vertex
Add that edge and vertex to tree
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
Priority Queue (by key)
MST Weight:
0
Reset
▶ Start
Step →