Minimum spanning tree

Jimmy (xiaoke) Shen
1 min readJun 21, 2020

--

How to find all the minimum spanning tree?

See[1]

“Find the MST of the graph using kruskal’s or prim’s algorithm. This should be O(E log V).

Generate all spanning trees. This can be done in 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.

Filter the list generated in step #2 by the tree’s weight being equal to the MST’s weight. This should be O(n) for n as the number of trees generated in step #2.

Note: Do this lazily! Generating all possible trees and then filtering the results will take O(V²) 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

Problem

https://leetcode.com/contest/weekly-contest-194/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/

Reference

[1]https://stackoverflow.com/questions/2935754/all-minimum-spanning-trees-implementation

--

--

No responses yet