Finding Minimum Spanning Tree in O(N+M) Time

Finding Minimum Spanning Tree in O(N+M) Time
$\begingroup$

I am now learning about MST and algorithms for finding it, like Prim's, Kruskal's and etc. However, what if we have a connected, undirected simple graph and all edges have a weight, BUT the possible weights are {1,10,100,1000}. Is it possible to find MST in O(m+n) time? I know that the data structure matters when we are talking about the time complexity, and we can use something like Fibonacci heaps to make it faster, but still, I have no idea how to make an algorithm with the running time O(n+m).

$\endgroup$

1 Answer

$\begingroup$

Using Prim's algorithm, you can achieve an $\mathcal{O}(n+m)$ complexity by using a bucket priority queue. This priority queue has all operations complexity constant or bounded by the number of possible weights, so constant in this case.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.