Kruskal's algorithm
medium 20 minKruskal's algorithm finds a minimum spanning tree: the cheapest set of edges that connects every vertex with no cycles.
Where it shows up
The same pattern appears across everyday software.
Network and cable design
Laying fibre, power lines, water pipes or LAN cables to connect every site at the least total cost is the textbook MST problem. Kruskal works straight from the list of possible links and their costs.
Circuit and chip wiring
Connecting pins that must share a signal with the least total wire length uses MSTs as a fast first approximation to the harder Steiner tree problem in routing tools.
Clustering
Single-linkage hierarchical clustering is Kruskal stopped early: merge the closest pair of groups until k remain. It is used for grouping documents, genes and customer segments.
Image segmentation
The Felzenszwalb-Huttenlocher graph-based segmentation algorithm treats pixels as vertices and colour differences as weights, then processes edges in Kruskal order with union-find to merge similar regions.
Approximating the travelling salesman
For distances that obey the triangle inequality, walking an MST and skipping repeated cities gives a tour at most twice the optimum, and the MST is also the base of Christofides' 1.5-approximation.
Maze generation
A randomised Kruskal over a grid of cells, with random edge weights, knocks down walls only between cells not yet connected. The result is a perfect maze: exactly one path between any two cells.