2,556 views
4 votes
4 votes
I mean if we run prim's algorithm on a weighted directed graph, will it give the same shortest path? And vice-versa?

Also if we run dijkstra's algorithm on a graph with negative weight cycle reachable from source, what will happen?

What if we run kruskal's MST algorithm on a graph with negative weights and negative weight cycles?

Thanks in advance.

2 Answers

Best answer
1 votes
1 votes

1.from prims algo. - we will get MST

from dijsktra algo - we will get shortest path from source(i.e single source) to destination.

2. if we run dijsktra on graph with negative weight edges then dijsktra algo is going to compute the shortest path but it may or may not be correct .since it is not a sin to run dijsktra algo with graph having negative weight edges .And becoz of this demerit of dijsktra algo. we switch to bellman ford algo.

since practically it is not possible to have negative wieght edges (for ex -travelling salesman problem ) therefore dijskta algo is more practically used as compared to bellman ford algo.

3. kruskal algo is also an algo so u can run it with graph containing negative weight edges and negative weight cycles since the output will be an tree(without cycles) not an graph.

selected by

Related questions

1 votes
1 votes
2 answers
1
Sankaranarayanan P.N asked Jun 25, 2015
578 views
When can we have single source shortest path algorihm runs in Big Oh of number of edges.Options are like weighted graph, undirected graph, undirected and weighted, not po...
1 votes
1 votes
1 answer
2
5 votes
5 votes
3 answers
3
Kapil asked Jan 24, 2017
3,414 views
It may be the case that "Kruskal's Algorithm may not maintain connectivity while Prim's algorithm always does that" ?Any example which favours this ?