Kruskal’s Algorithm

Learn about Kruskal’s algorithm and its applications in solving the minimum spanning trees problem

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:

  • Kruskal:Kruskal: Scan all edges by increasing weight; if an edge is safe, add it to FF.

In the below illustration, Kruskal’s algorithm runs on the example graph. Thick red edges are in FF; 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 O(ElogE)O(E \log E) 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 FF. Suppose we encounter an edge ee that joins two components AA and BB but is not safe. Then there must be a lighter edge ee^′ with exactly one endpoint in AA. But this is impossible, because (inductively) every previously examined edge has both endpoints in the same component of F ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy