Kruskal’s algorithm to find the minimum cost spanning tree uses the greedy approach. This algorithm treats the graph as a forest and every node it has as an individual tree. A tree connects to another only and only if, it has the least cost among all available options and does not violate MST(Minimum spanning tree) properties.
Kruskal’s algorithm
create a forest F (a set of trees), where each vertex in the graph is a separate tree
create a set S containing all the edges in the graph
while S is nonempty and F is not yet spanning
remove an edge with minimum weight from S
if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree
At the termination of the algorithm, the forest forms a minimum spanning forest of the graph. If the graph is connected, the forest has a single component and forms a minimum spanning tree
Kruskal’s algorithm can be shown to run in O(E log E) time, or equivalently, O(E log V) time, where E is the number of edges in the graph and V is the number of vertices.
Program in C :
Output:
Please comment below in case of any problem found during running the code or any other doubts.
Computer Science Major, Bioinformatics Bachelor, Deep Learning enthusiast, hard core Gamer , occasional Philosopher, avid music listener and movie lover. Visit my other blog for Gaming and Technical review related posts @ Blogger; also feel free to post a question @ Quora (links below)
How to modify Service Fabric replicator log size and also how to change Service Fabric Local cluster installtion directory or log directory. Continue reading