Start here · Essential guide
Prim's Algorithm vs. Kruskal's
Prim's and Kruskal's both find a minimum spanning tree. Compare how each builds it, their steps, running times, and which fits sparse or dense graphs.
Algorithms
How the Prim and Kruskal algorithms build minimum spanning trees, step by step.
Start here · Essential guide
Prim's and Kruskal's both find a minimum spanning tree. Compare how each builds it, their steps, running times, and which fits sparse or dense graphs.
Prim's or Kruskal's, which is easier? Each relies on different tools. This compares the code, the hand tracing, and where sources disagree on the answer.
Prim's algorithm grows one tree from a starting vertex, always adding the cheapest edge that reaches a new vertex. Steps, a worked example, and running time.
Kruskal's algorithm runs in O(E log E) time, usually written O(E log V). Here is where that time goes, and what the word order means in Big O notation.
Kruskal's algorithm sorts edges and skips any that form a loop, giving the cheapest way to connect every vertex. Here is why it is used and when it fits.
Related topics