# Kruskal’s Algorithm C Program

By | October 1, 2016

## C Program To Implement Kruskal’s Algorithm For Minimum Spanning Tree

Learn How To Create a Minimum Spanning Tree using Kruskal’s Algorithm in C Programming Language. Kruskal’s Algorithm is a Greedy Algorithm approach that works best by taking the nearest optimum solution.

#### What is Minimum Spanning Tree?

A Spanning Tree of any graph G whose sum of the weights is minimum amongst all the spanning trees of G, is called the Minimum Spanning Tree of the graph G.

#### What is Kruskal’s Algorithm?

Kruskal’s algorithm is a minimum spanning tree algorithm to find an Edge of the least possible weight that connects any two trees in a given forest. Initially, a forest of n different trees for n vertices of the graph are considered. Each tee is a single vertex tree and it does not possess any edges. In every iteration, an edge is considered and it is included in the spanning tree if it does not form a cycle. If it forms a cycle, then it is not included.

#### Steps for Kruskal’s Algorithm

1. Sort all the Edges in the increasing order
2. Find the Edge with the minimum weight
3. Include it if it does not form a cycle
4. Repeat the above steps till v – 1 Edges where v is the total number of vertices

The Kruskals Algorithm is faster than Prim’s Algorithm as in Prim’s Algorithm, an Edge may be considered more than once whereas in Kruskal’s Algorithm, an Edge is considered only once.

Must Read: C Program To Implement Prim’s Algorithm

#### C Program To Implement Kruskal’s Algorithm to Find Minimum Spanning Tree

Must Read: C Program To Implement Warshall’s Algorithm

#### Output

In case you get any Compilation Errors or any doubts in this Code To Make Minimum Spanning Tree using Kruskal’s Algorithm in C Programming, let us know about it in the Comment Section below. Check this article on GeeksforGeeks for more information on Kruskals Algorithm.

## One thought on “Kruskal’s Algorithm C Program”

1. Mickey Ahuja

A Minimum Spanning Tree is an application of a Disjoint Data Structure.