Prim’s Algorithm definition
Prim’s algorithm grows a minimum spanning tree one vertex at a time by choosing a lightest edge from the current tree to a new vertex.
Prim’s Algorithm in a picture
How it works
Start from any vertex of a connected weighted undirected graph. At each step, compare edges with one endpoint in the growing tree and the other outside. Add one with minimum weight, along with its outside endpoint, until all vertices are included.
Worked examples
A–B weighs 3 and A–C weighs 5. Starting at A, which is chosen first?
A–B.
If B–C weighs 2, which edge is next?
B–C, the lighter edge crossing from {A, B} to C.
What can happen if two crossing edges tie?
Either can be chosen. The minimum total weight remains the same, though the tree may differ.
Common mistake
Compare individual crossing edge weights. Dijkstra instead compares tentative path totals from a start.
Quick check
Can the start vertex be chosen freely?
Show answer
Yes, in a connected graph.
How many accepted edges connect n vertices?
Show answer
n − 1.
Sources
Flashcard
Prim’s Algorithm
Reveal the definition
Prim’s algorithm grows a minimum spanning tree one vertex at a time by choosing a lightest edge from the current tree to a new vertex.
Effortless Math. “Prim’s Algorithm.” Math Dictionary.



