Loading...
Greedy MST formation by selecting safe edges in non-decreasing weight order validated through Disjoint Set Union cycle tests.
Kruskal's algorithm builds a minimum spanning tree by scanning edges in non-decreasing weight order and greedily adding those that do not form a cycle (detected via Disjoint Set Union). It treats the graph as a forest that gradually merges.
Sorting dominates. With union-find path compression + union by rank, per operation is almost constant (inverse Ackermann).
Algorithm | Best For | Approach | Time |
---|---|---|---|
Prim (Heap) | Dense graphs | Grow tree | O(m log n) |
Kruskal | Sparse / Edge-sorted reuse | Merge forests | O(m log n) |
Borůvka | Parallelizable | Component merges | O(m log n) |
Learn the cut property and DSU mechanics, then watch edges accepted/rejected in order.