Kruskal's Algorithm finds the Minimum Spanning Tree (MST) of a connected weighted graph by sorting all edges by weight and adding them using Union-Find cycle detection.
Connect 10 towns with electric cables. Sort all possible cable costs and lay down the cheapest cables first, skipping any cable that creates an electrical loop.
~4,483 steps (Linearithmic)
O((V + E) log V) Time
O(V + E) Graph Memory
Memory growth rate as N expands.
Relative efficiency rating for large N.
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Kruskal MST Time | O(E log E) | O(V + E) |
function kruskal(numVertices, edges) {
edges.sort((a, b) => a.weight - b.weight);
const dsu = new DisjointSet(numVertices);
const mst = [];
for (const edge of edges) {
if (dsu.union(edge.u, edge.v)) mst.push(edge);
}
return mst;
}Lays fiber-optic cables connecting cities at minimal infrastructure cost.
Validate your conceptual understanding, operation mechanics, and core concepts of Kruskal.
Always use path compression and rank optimization inside Union-Find to achieve near-constant $O(\alpha(V))$ set operations!
Graph loaded. Click Find MST to sort edges and build the Minimum Spanning Tree.