1
$\begingroup$

So i know that it cannot be used if the directed graph has negative cycle, but what about the undirected graphs with negative edges?

is it going to always work, or sometimes or never?

$\endgroup$
1

1 Answer 1

2
$\begingroup$

Floyd–Warshall can be used to detect the presence of negative cycles in directed graphs. This aspect has been widely used in the scheduling community in the form of detecting consistency of a simple temporal network. To answer your question, the values output by Floyd–Warshall will be correct even in the presence of negative edges as long as there are no negative cycles.

$\endgroup$
2
  • $\begingroup$ But if there is a negative edge on a undirected graph, that means there is a negative cycle right? i mean shouldn't we convert the undirected edges to 2 directed edges? $\endgroup$
    – John P
    Commented Mar 20, 2018 at 13:16
  • $\begingroup$ Yes, you would need to convert the undirected edges to directed edges. I apologize, I dint read your question properly earlier. The following may be helpful. I guess you are interested in computing shortest simple paths between vertices. It is known that when there are negative cycles, the problem of computing shortest paths is NP-Complete (can be reduced from longest path problem). $\endgroup$ Commented Mar 20, 2018 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.