Algorithm
Kruskal's minimum spanning tree
activeNeeds verification
Builds a minimum-weight spanning tree by adding edges in increasing weight order whenever they join two different components.
Intuition
Greedily take the cheapest remaining edge that does not create a cycle; a union–find structure tracks components.
Pseudocode
Kruskal(G):
T = ∅; make_set(v) for all v
for (u, v) in edges sorted by weight:
if find(u) != find(v): T.add((u, v)); union(u, v)
return T
Complexity
| Time | O(E log E) |
|---|---|
| Space | O(V) |
Python
import networkx as nx
T = nx.minimum_spanning_tree(G, algorithm='kruskal', weight='weight')An interactive step-by-step visualizer for this algorithm is planned for phase 3.
Profile
| Time complexity | O(E log E) |
|---|---|
| Space complexity | O(V) |
Relationships
- Belongs to
- Related
- Kruskal's minimum spanning tree algorithm(Timeline event)