Skip to main content

Module spanning_trees

Module spanning_trees 

Source
Expand description

Minimum spanning trees (forests) of undirected graphs: Kruskal and Prim.

See the book entry Minimum spanning trees and union-find.

Structs§

SpanningForest
A minimum spanning forest: its edges and total weight (one tree per connected component).

Functions§

kruskal
Kruskal’s algorithm: edges by increasing weight, kept when they join two components (union-find). O(E log E).
prim
Prim’s algorithm: grows each tree from a root by the cheapest edge leaving it (binary heap). O(E log V); better than Kruskal on dense graphs.