First please note that this question is NOT asking about MST, instead, just all possible spanning trees.
So this is NOT the same as finding all minimal spanning trees or All minimum spanning trees implementation
I just need to generate all possible spanning trees from a graph.
I think the brute-force way is straight:
Suppose we have V nodes and E edges.
- Get all edges of the graph
- Get all possible combinations of
V-1out ofEedges. - Filter out
non-spanning-treeout of the combinations (for a spanning tree, all nodes inside one set ofV-1edges should appear exactly once)
But I think it is too slow when facing big graph.
Do we have a better way?