I've been looking for an implementation (I'm using networkx library.) that will find all the minimum spanning trees (MST) of an undirected weighted graph.
I can only find implementations for Kruskal's Algorithm and Prim's Algorithm both of which will only return a single MST.
I've seen papers that address this problem (such as Representing all minimum spanning trees with applications to counting and generation) but my head tends to explode someway through trying to think how to translate it to code.
In fact i've not been able to find an implementation in any language!
If a graph is a complete graph with n vertices, then total number of spanning trees is n(n-2) where n is the number of nodes in the graph. In complete graph, the task is equal to counting different labeled trees with n nodes for which have Cayley's formula.
It is also known as the DJP (Dijkstra-Jarnik Problem) algorithm, or the Jarnik algorithm, or the Prim–Jarnik algorithm. The prim's algorithm is the greedy algorithm used to find the minimum cost spanning tree for an undirected weighted graph.
I don't know if this is the solution, but it's a solution (it's the graph version of a brute force, I would say):
O(Elog(V) + V + n) for n = number of spanning trees
, as I understand from 2 minutes's worth of google, can possibly be improved.Note: Do this lazily! Generating all possible trees and then filtering the results will take O(V^2) memory, and polynomial space requirements are evil - Generate a tree, examine it's weight, if it's an MST add it to a result list, if not - discard it.
Overall time complexity: O(Elog(V) + V + n) for G(V,E) with n spanning trees
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With