Question

Hey i have been studying the bellman ford algorithm for "single source shortest path" problems.

Now i am stuck at one point where i need to find out the solution for a graph having negative weight cycle.

But Bellman ford algorithm does not work here.

Can some one suggest me what to do. How to solve a problem having negative weight cycle?

Thanks for your time.

Était-ce utile?

La solution

If there is a negative cycle which is reachable from the origin, which Bellman-Ford can detect, then you have two choices: either allow repeating edges, or do not. If you allow repeating edges, your shortest path could be considered to be infinitely negative. Otherwise, if you do not, the problem is NP complete. From Wikipedia:

One NP-Complete variant of the shortest-path problem asks for the shortest path in G (containing a negative cycle) such that no edge is repeated.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top