I know that the problem of checking whether given edge of a weighted digraph belongs to a negative cycle is NP-complete (Finding the minimal subgraph that contains all negative cycles) and Bellman-Ford allows to check a vertex for the same thing in O(|V|*|E|) time. But what if I want to find all vertices belonging to negative cycles? I wonder if it could be done faster than Floyd-Warshall's O(|V|^3).

- 1
- 1

- 835
- 4
- 15
-
hmm not hard enough to be on theory, not programmable enough to be on SO. – Woot4Moo May 23 '13 at 17:54
-
Why wouldn't Bellman-Ford give you that info? All vertices that have their distances updated in the n-th phase must be on a negative weight cycle, no? – G. Bach May 23 '13 at 18:25
-
They could be as well reachable from a negative cycle – tempestadept May 23 '13 at 18:32
-
Oh yeah, I made a think-o, you're right. – G. Bach May 23 '13 at 18:35
-
@Woot4Moo Read the FAQ: "if your question generally covers …a software algorithm … then you’re in the right place to ask your question!" – David Eisenstat May 23 '13 at 22:40
-
@DavidEisenstat i am familiar with the FAQ, I think this is more theory, but not enough theory if you follow. – Woot4Moo May 23 '13 at 22:41
-
@Woot4Moo No, I don't follow. How is this not a question about a software algorithm? – David Eisenstat May 23 '13 at 22:55
-
It's off-topic for cstheory by the way (not research-level). – David Eisenstat May 23 '13 at 22:57
-
@DavidEisenstat are you sure it isn't research level? Because that implies that you have a solution for this graph theory problem. – Woot4Moo May 23 '13 at 23:05
1 Answers
I don't think Floyd-Warshall does the job of finding these vertices. Using a similar approach as taken in the post you're referring to, it can be shown that finding the set of all vertices that lie on a negative cycle is NP-complete as well.
The related post shows that one may use the algorithm to find the set of all edges that lie on a negative cycle to solve the hamiltonian cycle problem, which means that the former problem is NP-complete. If we can reduce the problem of finding all edges that lie on a negative cycle to the problem of finding the set of all vertices that lie on a negative cycle, we've shown NP-completeness of the latter problem.
For each edge (u,w) in your weighted digraph, introduce a new auxiliary vertex v, and split (u, w) in two edges (u, v) and (v, w). The weight of (u, w) can be assigned to either (u, v) or (v, w). Now apply the magic polynomial-time algorithm to find all the vertices that lie on a negative cycle, and take the subset that consists of the auxiliary vertices. Since each auxiliary vertex is associated with an edge, we've solved the problem of finding the minimal subgraph that contains all negative cycles, and we can thus also solve the hamiltonian cycle problem in polynomial time, which implies P = NP. Assuming P != NP, finding all vertices that lie on a negative cycle is NP-complete.

- 131
- 7
-
Ok, I've understood my mistake. Bellman-Ford checks for not necessarily simple cycle, and finding a simple cycle is indeed NP-complete. Thank you. – tempestadept May 24 '13 at 09:25