What is the Kruskal's algorithm for finding the minimum spanning tree in a graph?

Graph Theory Questions Medium



63 Short 66 Medium 48 Long Answer Questions Question Index

What is the Kruskal's algorithm for finding the minimum spanning tree in a graph?

Kruskal's algorithm is a greedy algorithm used to find the minimum spanning tree (MST) in a graph. The algorithm works as follows:

1. Sort all the edges of the graph in non-decreasing order of their weights.
2. Create an empty set called the MST, which will eventually contain the edges of the minimum spanning tree.
3. Iterate through the sorted edges, starting from the smallest weight.
4. For each edge, check if adding it to the MST creates a cycle. If not, add the edge to the MST.
5. Continue this process until all the vertices are included in the MST or there are no more edges left.
6. Return the MST.

To check if adding an edge creates a cycle, a disjoint-set data structure is commonly used. This data structure keeps track of the connected components of the graph and allows efficient cycle detection.

Kruskal's algorithm guarantees that the resulting MST will have the minimum total weight among all possible spanning trees in the graph. It is efficient and has a time complexity of O(E log E), where E is the number of edges in the graph.