Graph/mst_kruskal library

🌲 Kruskal's Algorithm (Minimum Spanning Tree/Forest)

Finds a minimum spanning forest by sorting edges by weight and adding them greedily while avoiding cycles using a Union-Find (Disjoint Set).

  • Input: nodes set and undirected edges
  • Time complexity: O(E log E)
  • Space complexity: O(V)

Returns the list of edges in the MST (or MSF if graph is disconnected).

Functions

kruskalMST<T>(Set<T> nodes, List<WeightedEdge<T>> edges) → List<WeightedEdge<T>>