Kruskal's algorithm is a minimum-spanning-tree algorithm which finds an edge of the least possible weight that connects any two trees in the forest. It is a greedy algorithm in graph theory as it finds a minimum spanning tree for a connected weighted graph adding increasing cost arcs at each step. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. If the graph is not connected, then it finds a minimum spanning forest (a minimum spanning tree for each connected component).

A demo for Kruskal's algorithm based on Euclidean distance.

A **minimum spanning tree** (MST) or minimum weight spanning tree is a subset of the edges of a connected, edge-weighted (un)directed graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight. That is, it is a spanning tree whose sum of edge weights is as small as possible. More generally, any edge-weighted undirected graph (not necessarily connected) has a minimum spanning forest, which is a union of the minimum spanning trees for its connected components.

A planar graph and its minimum spanning tree. Each edge is labeled with its weight, which here is roughly proportional to its length.

This figure shows there may be more than one minimum spanning tree in a graph. In the figure, the two trees below the graph are two possibilities of minimum spanning tree of the given graph.

- Minimum Spanning Tree on Wikipedia
- Kruskal's Algorithm on Wikipedia
- Kruskal's Algorithm on YouTube by Tushar Roy
- Kruskal's Algorithm on YouTube by Michael Sambol

TheOriginal Articlecan be found onhttps://github.com

#javascript #algorithms #datastructures #graphs

1.50 GEEK