Is Minimum Spanning Tree afraid of negative weights?

Jackson Tale picture Jackson Tale · May 2, 2012 · Viewed 37.8k times · Source

This is a follow-up question of Why most graph algorithms do not adapt so easily to negative numbers?.

I think Shortest Path (SP) has problem with negative weights, because it adds up all weights along the paths and tries to find the minimum one.

But I don't think Minimum Spanning Tree (MST) has problems with negative weights, because it just takes the single minimum weight edge without caring about the overall total weights.

Am I right?

Answer

Skiminok picture Skiminok · May 2, 2012

Yes, you are right. The concept of MST allows weights of an arbitrary sign. The two most popular algorithms for finding MST (Kruskal's and Prim's) work fine with negative edges.

Actually, you can just add a big positive constant to all the edges of your graph, making all the edges positive. The MST (as a subset of edges) will remain the same.