Is Minimum Spanning Tree afraid of negative weights?

AlgorithmData StructuresGraphMinimum Spanning-Tree

Algorithm Problem Overview


This is a follow-up question of https://stackoverflow.com/questions/10381474/graph-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?

Algorithm Solutions


Solution 1 - Algorithm

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.

Solution 2 - Algorithm

Yes, you are right because if you see the algorithm for shortest path like dijkstera it will check if the present distance of vertex v is greater than sum of present value + edge weight then it will change the value of distance of vertex v from s by the sum value and if the edge weight is negative then it will give some problems.

But in the MST problem there are algorithms like prims,kruskal which take only the minimum weight edge so that make the negative edge qualify for MST.

Solution 3 - Algorithm

Yes,you are right Prim's algorithm works like dijkstra's algorithm but in prim's algorithm it should not compute shortest path from i to j having negative edges . So, their is an another algorithm is their i.e Bellman-Ford algorithm for compute shortest path from i to j with negative edge.

Therefore prim's and Kruskal's algorithm is not fear for negative edges.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJackson TaleView Question on Stackoverflow
Solution 1 - AlgorithmSkiminokView Answer on Stackoverflow
Solution 2 - AlgorithmRahul DhawanView Answer on Stackoverflow
Solution 3 - AlgorithmREVANASIDDAView Answer on Stackoverflow