Minimum Spanning Tree using kruskal algorithm

Here you will learn the program code to find minimum spanning tree using kruskal algorithm in C programming.

 

What is minimum spanning tree?

A minimum spanning tree is a subset of edges from a connected graph that connects all its vertices with the minimum possible total edge weight, forming a tree-like structure.

 

Spanning Tree Calculation

minimum spanning tree using kruskal algorithm

Image Source

 

C program to find minimum spanning tree using kruskal algorithm

Output

Input number of vertices : 3

Input cost adjacency matrix :
1
2
3
4
5
6
7
8
9

Edge 1 (0 -> 1) cost : 2
Edge 2 (0 -> 2) cost : 3
Minimum cost is : 5

Edges in MST are :

0 -> 2
1 -> 0
2 -> 0

 


 

Read Also

Implement N Queens Problem using Backtracking

1/2 Knapsack Problem Using Dynamic Programming in C

Knapsack Problem Using Greedy Solution

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top