Kruskal's algorithm

Kruskal's algorithm is a greedy algorithm to find a minimum spanning tree in a weighted, undirected graph. Joseph Kruskal first described it in 1956:

In this case, the shortest edge is the one with the lowest weight.

 Example 

Download the example data. 

 Image  Description200pxAD and CE are the shortest edges, with length 5, and AD has been arbitrarily chosen, so it is highlighted.200pxCE is now the shortest edge that does not form a cycle, with length 5, so it is highlighted as the second edge.200pxThe next edge, DF with length 6, is highlighted using much the same method.200pxThe next-shortest edges are AB and BE, both with length 7. AB is chosen arbitrarily, and is highlighted. The edge BD has been highlighted in red, because there already exists a path (in green) between B and D, so it would form a cycle (ABD) if it were chosen.200pxThe process continues to highlight the next-smallest edge, BE with length 7. Many more edges are highlighted in red at this stage: BC because it would form the loop BCE,  DE because it would form the loop DEBA, and FE because it would form FEBAD.200pxFinally, the process finishes with the edge EG of length 9, and the minimum spanning tree is found.
References

Category:Greedy algorithms
Category:Graph theory
Category:Combinatorial optimization