Kruskal’s Algorithm
Learn about Kruskal’s algorithm and its applications in solving the minimum spanning trees problem
We'll cover the following...
Introduction to Kruskal’s algorithm
The last minimum spanning tree algorithm we’ll consider was first described by Joseph Kruskal in 1956, in the same paper where he rediscovered Jarnik’s algorithm. Kruskal was motivated by “a typewritten translation (of obscure origin)” of Borůvka’s original paper that had been “floating around” the Princeton math department. Kruskal found Borůvka’s algorithm “unnecessarily elaborate.” The same algorithm was rediscovered in 1957 by Harry Loberman and Arnold Weinberger but somehow avoided being renamed after them.
Methodology
Like our earlier minimum spanning tree algorithms, Kruskal’s algorithm has a memorable one-line description:
- Scan all edges by increasing weight; if an edge is safe, add it to .
In the below illustration, Kruskal’s algorithm runs on the example graph. Thick red edges are in ; thin dashed edges are useless.
Kruskal’s algorithm for minimum spanning tree
The simplest method to scan the edges in increasing weight order is to sort the edges by weight, in time, and then use a simple for
loop over the sorted edge list. As we will see shortly, this preliminary sorting dominates the running time of the algorithm.
Because we examine the edges in order from lightest to heaviest, any edge we examine is safe if and only if its endpoints are in different components of the forest . Suppose we encounter an edge that joins two components and but is not safe. Then there must be a lighter edge with exactly one endpoint in . But this is impossible, because (inductively) every previously examined edge has both endpoints in the same component of ...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy