Skip to content

@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 ​

Graph

The undirected graph to compute the MST for

Returns ​

MSTResult

The minimum spanning tree as a set of edges and the total weight

Throws ​

Error if the graph is directed or not connected