Motivation
Lesson 2 of 9 in Coddy's Prim's Algorithm - Graph Algorithms course.
Where Kruskal sorts all edges globally and uses union-find, Prim keeps a single growing tree and repeatedly reaches for the nearest outside vertex.
Why learn Prim?
- Dense graphs: Prim with the right structures is efficient when there are many edges.
- Cut property: it is a hands-on illustration of why the cheapest edge leaving the current tree is always safe to add.
- Two views of one problem: comparing Prim and Kruskal deepens your understanding of minimum spanning trees.
Because all MSTs of a graph share the same edge weights, Prim and Kruskal always report the same total weight.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.