Kruskal's MST Algorithm
Kruskal's algorithm is a greedy algorithm used to find the Minimum Spanning Tree (MST) of a connected, undirected graph. An MST is a subgraph that connects all the vertices together, without any cycles and with the minimum possible total edge weight.
The algorithm works as follows:
- Create a list of all edges in the graph and sort them in non-decreasing order of their weights.
- Initialize the MST as an empty set.
- Initialize a Union-Find data structure with each vertex in its own set.
- Iterate through the sorted edges. For each edge
(u, v)
:- If
find(u)
is not equal tofind(v)
, it means that adding this edge will not form a cycle. - Add the edge to the MST and perform a
union(u, v)
.
- If
- The algorithm terminates when the MST has
V - 1
edges, whereV
is the number of vertices.
Kruskal's algorithm is particularly efficient for sparse graphs (graphs with relatively few edges). Its time complexity is dominated by the edge sorting step, which is O(E log E), where E is the number of edges.
Kruskal's Minimum Spanning Tree
Step 1 of 0
Action
Ready to start
MST Edges
0 / 6
Total Cost
0
Sorted Edges by Weight:
Current Edge
MST Edge
Rejected (Cycle)
Not Considered
Same Component
Network Infrastructure: Connect all communication towers with minimum cable cost. Nodes with same color are in the same connected component. Algorithm rejects edges that would create cycles.