Kruskal Algorithm

It is a greedy algorithm in graph theory as it finds a minimal spanning tree for a connected weighted graph adding increase price arcs at each step. If the graph is not connected, then it finds a minimal spanning forest (a minimal spanning tree for each connected component).

Kruskal source code, pseudocode and analysis

Make a forest F (a set of trees), where each vertex in the graph is a separate tree: -make a set S containing all the edges in the graph -while S is nonempty and F is not yet spanning -remove an edge with minimal weight from Sif the removed edge connects two different trees then add it to the forest F, combine two trees into a individual treeAt the termination of the algorithm, the forest forms a minimal spanning forest of the graph.