MathOverflow is a question and answer site for professional mathematicians. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose we have a weighted, acyclic digraph, with positive and negative edge weights.

Is there an algorithm that determines whether there is a path of weight zero between vertices A and B? The Bellman-Form algorithm finds the path of smallest weight - is there another algorithm that determines the path of smallest absolute value weight?

Thanks, Charles

share|cite|improve this question
What weights are allowable? Integers between -16 and 16? Arbitrary rational or real numbers? Something in between? (If there is a minimum gap between path weights, it might make the problem easier.) – Charles Staats Mar 11 '12 at 20:18
The weights are integers in the interval [-c,c] for some integer constant c. – Charles Bailey Mar 11 '12 at 20:23
If it's a finite graph, then of course there's an algorithm, exhaustive search. Perhaps your question is whether there is a more efficient algorithm? – Gerry Myerson Mar 11 '12 at 23:03
Yes, it's a finite graph, so exhaustive search would work. I'm looking for something more efficient. Thanks, Charles – Charles Bailey Mar 12 '12 at 2:55
up vote 6 down vote accepted

It is NP-complete if $c$ is not specified. For a set of numbers $m_1,\ldots,m_t$ make a digraph with vertices $v_0,v_1,\ldots,v_t$. From $v_{i+1}$ to $v_i$ put two edges, of length $m_i$ and $-m_i$, for each $i$. A path of zero length from $v_0$ to $v_t$ corresponds to a partition of $m_1,\ldots,m_t$ into two sets of equal size, which is a well known NP-complete problem (called PARTITION).

share|cite|improve this answer
That still leaves the question of whether any practical algorithms exist, at least to find "small" absolute values. There is the obvious convex relaxation, but it is not clear it works at all... – Igor Rivin Mar 12 '12 at 4:35
for weights given in unary, one might suspect that there will be a dynamic programming algorithm... – Dima Pasechnik Mar 13 '12 at 5:06
If the weights are integers of magnitude $O(c)$, then there is an $O(cnm)$ dynamic programming algorithm, where $m$ is the number of edges. For each vertex in topological order, determine which path lengths occur from the starting vertex to that vertex. It would be nice to know if faster is possible. – Brendan McKay Mar 13 '12 at 6:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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