Greedy algorithms and minimum spanning trees
Greedy algorithms make the locally best choice at each step; for some problems this gives the global optimum.
Edited by Alex C, EduAlx · Sources cited below
Explanation
Kruskal (1956) and Prim (1957, earlier Jarník 1930) find minimum spanning trees. Huffman coding and activity selection are greedy. Greedy correctness is proved by exchange arguments or matroid theory; it fails for problems like 0/1 knapsack.
Example
How it works, step by step
- Sort edges by weight
- Take the cheapest edge that does not form a cycle (union–find)
- Repeat until V–1 edges are chosen
- Result is a minimum spanning tree
Open the interactive page with diagrams →
People behind it
- Joseph Kruskal (1928–2010), Mathematics, USA: Gave Kruskal's minimum spanning tree algorithm (1956).
- Robert Prim
- Vojtěch Jarník
References
- J. B. Kruskal, Proc. Am. Math. Soc. 1956, 7, 48–50.
- R. C. Prim, Bell Syst. Tech. J. 1957, 36, 1389–1401.
Textbooks
- Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein (MIT Press, 4th ed. 2022). 'CLRS', the standard algorithms text.
Related topics
String algorithms and pattern matchingDynamic programmingAlgorithms and Big-O complexityGraph algorithms: BFS, DFS and Dijkstra's shortest pathSorting algorithms (quicksort, mergesort, heapsort)Heaps and priority queuesAutomata and formal languagesRecursionMemory hierarchy and cachesNumber systems and data representation