@graphty/algorithms / index / kruskalMST
Function: kruskalMST() ​
kruskalMST(
graph):MSTResult
Defined in: algorithms/mst/kruskal.ts:18
Computes the minimum spanning tree of an undirected graph using Kruskal's algorithm. The algorithm sorts edges by weight and greedily adds edges that don't create cycles, using a union-find data structure to efficiently detect cycles.
Parameters ​
graph ​
The undirected graph to compute the MST for
Returns ​
The minimum spanning tree as a set of edges and the total weight
Throws ​
Error if the graph is directed or not connected