Kruskal's Algorithm
Kruskal's Algorithm
Kruskal's Algorithm
Kruskal's algorithm is a popular method for finding the minimum spanning tree (MST) of a graph.
It is a greedy algorithm that builds a spanning tree by adding edges one by one from the set of all edges of the graph.
The key idea is to:
- start with each vertex forming a separate tree;
- gradually merge these trees by adding minimum-weight edges that do not form cycles.
Steps of the algorithm
-
Sorting edges
Sort all edges of the graph in nondecreasing order by their weight. -
Initialization
Create a forest consisting of trees, where each tree contains exactly one vertex. -
Selecting edges
Repeat the following actions until the forest becomes one tree:- take the smallest-weight edge that does not create a cycle (its ends belong to different trees);
- add this edge to the forest , merging two trees.
-
Result
The resulting forest is the minimum spanning tree of the graph.