This is the implementation of Kruskal’s Algorithm in C Programming Language. This algorithm is directly based on the generic MST (Minimum Spanning Tree) algorithm.

Kruskal’s algorithm is a greedy algorithm in graph theory that finds a minimum spanning tree for a connected weighted graph. It finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized.

Kruskal’s algorithm addresses two problems as mentioned below.

PROBLEM 1. Give a practical method for constructing a spanning subtree of minimum length.

PROBLEM 2. Give a practical method for constructing an unbranched spanning subtree of minimum length.

Kruskal’s algorithm is most suitable for sparse graphs (low number of edges).  This algorithm is practically used in many fields such as Traveling Salesman Problem, Creating Mazes and Computer Networks etc.

Pseudo code for the Kruskal’s Algorithm

Complexity of Kruskal’s Algorithm

The time complexity Of Kruskal’s Algorithm is: O(e log e).

C Programming Implementation of Kruskal’s Algorithm

Output of the C Program