Skip to main content

Module spanning_tree

Module spanning_tree 

Source
Expand description

Minimum and maximum spanning forests over CSR adjacencies.

Kruskal with union-find. The adjacency is read as undirected: a stored entry connects its endpoints whichever direction it sits in, so a directed CSR needs no transpose. Where a pair is stored in both directions with different weights, the weight that favours the objective wins (smaller for the minimum forest, larger for the maximum one).

Disconnected input yields a forest rather than an error, matching scipy.sparse.csgraph.minimum_spanning_tree. Two deliberate divergences from that routine: explicitly stored zero weights are kept as real edges (scipy treats a zero as an absent edge), and ties resolve by (weight, lo, hi) so the output does not depend on traversal order.

Functionsยง

maximum_spanning_forest
Maximum spanning forest of a CSR adjacency.
minimum_spanning_forest
Minimum spanning forest of a CSR adjacency.