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:
nodesset and undirectededges - 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< edges) → List<T> >WeightedEdge< T> >