Krushed
Krushed
ON
“KRUSKAL ALGORITHIM, ON MINIMUM SPANNING TREES”
Course: Data Structure and Algorithm
SUBMITTED TO
SUBMITTED BY
Abstract.
Kruskal's Algorithm is an algorithm used to find the minimum spanning tree in graphical
connectivity that provides the option to continue processing the least-weighted margins. In
the Kruskal algorithm, ordering the weight of the ribs makes it easy to find the shortest
path. This algorithm is independent in nature which will facilitate and improve path
creation.
Kruskal’s algorithm is one to find minimum spanning tree in a graph connectivity which gives
options of always processing the edge limit with the least weight. This algorithm run by
considering the graph’s biggest edge limit when searching for track in node in a graph which
has been put into a spanning tree. If an edge limit is considered will integrate (with one of
the points not in the spanning tree), or the integration of a point in spanning tree (one of
which is not in the spanning tree), then the edge limit and the final point is included in the
spanning tree. Considering one of the edge limits, algorithm continues by considering the
next larger edge limit weight. In this term, when the edge limit weight values are the same,
then it is unnecessary to determine which weight must be chosen first. Algorithm will stop
when every point have been included in the spanning tree. Note that, when spanning tree
was made, there was a possibility that the edge limit is not connected with the part of the
main tree, although in the end they will integrate with the main three.
Kruskal's Algorithm:
An algorithm to construct a Minimum Spanning Tree for a connected weighted
graph. It is a Greedy Algorithm. The Greedy Choice is to put the smallest weight edge
that does not because a cycle in the MST constructed so far.
If the graph is not linked, then it finds a Minimum Spanning Tree.
1. O (E log E) = O (E log V).
For Example: Find the Minimum Spanning Tree of the following graph using
Kruskal's algorithm.
Solution: First we initialize the set A to the empty set and create |v| trees, one
containing each vertex with MAKE-SET procedure. Then sort the edges in E into order
by non-decreasing weight.
Now, check for each edge (u, v) whether the endpoints u and v belong to the same
tree. If they do then the edge (u, v) cannot be supplementary. Otherwise, the two
vertices belong to different trees, and the edge (u, v) is added to A, and the vertices
in two trees are merged in by union procedure.
Step 3: then (a, b) and (i, g) edges are considered, and the forest becomes
Step 4: Now, edge (h, i). Both h and i vertices are in the same set. Thus it creates a
cycle. So this edge is discarded.
Then edge (c, d), (b, c), (a, h), (d, e), (e, f) are considered, and the forest becomes.
Step 5: In (e, f) edge both endpoints e and f exist in the same tree so discarded this
edge. Then (b, h) edge, it also creates a cycle.
Step 6: After that edge (d, f) and the final spanning tree is shown as in dark lines.
Step 7: This step will be required Minimum Spanning Tree because it contains all the
9 vertices and (9 - 1) = 8 edges
1. e → f, b → h, d → f [cycle will be formed]
// Kruskal's algorithm in C
#include <stdio.h>
#define MAX 30
edge_list elist;
int Graph[MAX][MAX], n;
edge_list spanlist;
void kruskalAlgo();
int find(int belongs[], int vertexno);
void applyUnion(int belongs[], int c1, int c2);
void sort();
void print();
sort();
spanlist.n = 0;
if (cno1 != cno2) {
spanlist.data[spanlist.n] = elist.data[i];
spanlist.n = spanlist.n + 1;
applyUnion(belongs, cno1, cno2);
}
}
}
// Sorting algo
void sort() {
int i, j;
edge temp;
int main() {
int i, j, total_cost;
n = 6;
Graph[0][0] = 0;
Graph[0][1] = 4;
Graph[0][2] = 4;
Graph[0][3] = 0;
Graph[0][4] = 0;
Graph[0][5] = 0;
Graph[0][6] = 0;
Graph[1][0] = 4;
Graph[1][1] = 0;
Graph[1][2] = 2;
Graph[1][3] = 0;
Graph[1][4] = 0;
Graph[1][5] = 0;
Graph[1][6] = 0;
Graph[2][0] = 4;
Graph[2][1] = 2;
Graph[2][2] = 0;
Graph[2][3] = 3;
Graph[2][4] = 4;
Graph[2][5] = 0;
Graph[2][6] = 0;
Graph[3][0] = 0;
Graph[3][1] = 0;
Graph[3][2] = 3;
Graph[3][3] = 0;
Graph[3][4] = 3;
Graph[3][5] = 0;
Graph[3][6] = 0;
Graph[4][0] = 0;
Graph[4][1] = 0;
Graph[4][2] = 4;
Graph[4][3] = 3;
Graph[4][4] = 0;
Graph[4][5] = 0;
Graph[4][6] = 0;
Graph[5][0] = 0;
Graph[5][1] = 0;
Graph[5][2] = 2;
Graph[5][3] = 0;
Graph[5][4] = 3;
Graph[5][5] = 0;
Graph[5][6] = 0;
kruskalAlgo();
print();
}