Skip to main content

Kruskal's Algorithm

Kruskal's Algorithm is a method for finding a minimum spanning tree in a weighted graph by choosing edges from smallest to largest while skipping any edge that creates a cycle. In Combinatorics, it shows how greedy choices can build an optimal network.

Last updated July 2026•Fiveable Content Team

What is Kruskal's Algorithm?

Kruskal's Algorithm is a greedy method in Combinatorics for building a minimum spanning tree from a weighted, undirected graph. You sort all edges from lightest to heaviest, then add an edge only if it connects two different parts of the graph and does not create a cycle.

The big idea is that the algorithm makes local choices that stay safe globally. A light edge is not automatically chosen just because it is small, though. It has to connect separate components, because if it closes a loop, it would make the tree less efficient without helping you reach a new vertex.

A minimum spanning tree is a spanning tree with the smallest possible total weight. That means it still touches every vertex, but it uses exactly n - 1 edges for n vertices and avoids extra connections. Kruskal's Algorithm works especially well when the graph is sparse, because there are fewer edges to sort and check.

To keep track of which vertices are already connected, the algorithm usually uses union-find, also called disjoint sets. That data structure tells you quickly whether two endpoints are already in the same component. If they are, adding the edge would form a cycle, so you skip it.

A small example makes the process easier to see. Suppose you have four vertices and weighted edges 1, 2, 3, 4, and 5. Kruskal's Algorithm takes edge 1, then edge 2 if it does not create a cycle, then keeps moving upward in weight until all vertices are connected. If the graph is disconnected, you do not get one spanning tree, you get a minimum spanning forest, one tree per connected part.

Why Kruskal's Algorithm matters in COMBINATORICS

Kruskal's Algorithm shows up when Combinatorics moves from counting objects to optimizing networks. It is one of the cleanest examples of a greedy algorithm, so it helps you see how a rule like "take the smallest safe edge" can produce a globally best answer instead of just a decent one.

It also ties together several graph topics at once. You need to recognize graph representations, know what a tree and spanning tree are, and understand why cycles matter. That makes it a useful bridge between abstract graph theory and algorithmic thinking.

The algorithm is also a good place to think about complexity. Since the edges must be sorted first, the running time is usually described as O(E log E), which makes the sorting step the bottleneck. That matters when you compare Kruskal's Algorithm with other MST methods or when you explain why it works better on sparse graphs.

In problem sets, this is the kind of method where accuracy matters more than memorizing a slogan. If you can trace the edge choices and justify each skip with cycle logic, you are already doing the core work the course asks for.

Keep studying COMBINATORICS Unit 10

Official unit cheatsheet

open one-pager

How Kruskal's Algorithm connects across the course

Minimum Spanning Tree

Kruskal's Algorithm is one way to find a minimum spanning tree, so you need the MST definition first. The tree must connect every vertex, use no cycles, and have the smallest total edge weight possible. If you do not know what counts as a spanning tree, Kruskal's steps will feel random instead of rule-based.

Union-Find

Union-find is the data structure that makes Kruskal's Algorithm efficient. It tracks which vertices already belong to the same component, so you can check whether a new edge would create a cycle. Without it, you would have to do much slower cycle checks by hand or with repeated graph searches.

Borůvka's Algorithm

Borůvka's Algorithm is another minimum spanning tree method, but it grows the tree differently. Instead of sorting every edge once and moving upward like Kruskal's Algorithm, Borůvka's approach repeatedly adds the cheapest edge leaving each component. Comparing the two helps you see different greedy strategies for the same MST goal.

Minimum-weight edge lemma

This lemma explains why picking a light edge can be safe in an MST argument. Kruskal's Algorithm depends on that same intuition, because it only accepts the smallest edge that does not create a cycle. When you justify a step in a proof, this is the kind of idea behind it.

Is Kruskal's Algorithm on the COMBINATORICS exam?

A problem set or quiz may give you a weighted graph and ask for the minimum spanning tree. You would sort the edges by weight, add the smallest edge that does not form a cycle, and continue until the graph is connected or you have a spanning forest. The real skill is not just listing the edges, it is explaining why each rejected edge was skipped.

If the graph is drawn as a table, adjacency matrix, or edge list, you still use the same logic. Students often lose points by picking a low-weight edge that closes a cycle too early, so checking component membership matters. If the graph is disconnected, be ready to say that Kruskal's Algorithm returns a minimum spanning forest instead of forcing one tree.

Kruskal's Algorithm vs Prim's Algorithm

Both Kruskal's and Prim's Algorithm find minimum spanning trees, but they grow the solution differently. Kruskal's Algorithm sorts all edges and adds the next safe edge anywhere in the graph, while Prim's Algorithm grows outward from one starting vertex. If a question asks about edge sorting and cycle checks, it is usually Kruskal's.

Key things to remember about Kruskal's Algorithm

  • Kruskal's Algorithm is a greedy method for finding a minimum spanning tree in a weighted, undirected graph.

  • It works by sorting edges from smallest to largest and adding only the ones that do not create a cycle.

  • Union-find is the usual tool for checking whether two vertices are already in the same component.

  • The algorithm is especially efficient for sparse graphs, and its runtime is usually driven by edge sorting.

  • If the graph is disconnected, the result is a minimum spanning forest, not one spanning tree.

Frequently asked questions about Kruskal's Algorithm

What is Kruskal's Algorithm in Combinatorics?

Kruskal's Algorithm is a greedy graph algorithm used to find a minimum spanning tree. It chooses edges in increasing order of weight and skips any edge that would create a cycle. In Combinatorics, it is a standard example of optimization with graphs.

How does Kruskal's Algorithm avoid cycles?

It avoids cycles by checking whether the two endpoints of an edge are already connected through earlier choices. If they are in the same component, adding the edge would make a loop, so the edge is rejected. This is why union-find is so useful with the algorithm.

What is the difference between Kruskal's Algorithm and Prim's Algorithm?

Both find minimum spanning trees, but Kruskal's Algorithm looks at all edges in increasing order and builds several components that merge over time. Prim's Algorithm starts from one vertex and expands a single tree outward. That difference is the easiest way to tell them apart on a graph problem.

Does Kruskal's Algorithm work on disconnected graphs?

Yes, but the result is a minimum spanning forest instead of one spanning tree. Each connected component gets its own tree. That is a common detail to mention when a graph is not fully connected.