Open Lekssays opened 8 years ago
Everything is inside the main (except for the union-find code); this makes code hard to follow. This is a solution file for some problem ! I think that it's better to have code that is independent of solutions to particular problems: just the algorithm itself. It's up to the user to apply it to solve problems. I prefer not reading input at all and just giving the algorithm with sufficient details for the user..(same applies for other issues).
Ye.This is a solution of a specific problem in which they asked to keep track of the connected edges as well. That's why I shared the whole solution. What do you suggest to show the way to keep track of the edges?
Problem: Minimum Spanning Tree: (Kruskal's Algorithm)
Input:
You are given a connected undirected graph G. You want to know what is the minimum spanning tree (a tree with the minimal total weighting of its edges )that connects all the vertices in the graph G.
Output:
Weight of the tree with the minimal total weighting of graph G's edges. (In this implementation, we displayed the edges that construct the MST)
Running Time:
E : Number of Edges, V : number of vertices
Implementation: