Re: Finding longest path between two vertices
- From: Googmeister <googmeister@xxxxxxxxx>
- Date: Mon, 18 Jun 2007 20:17:52 -0000
On Jun 18, 3:36 pm, Jym <Jean-Yves.Moyen+n...@xxxxxxxxxxxx> wrote:
On Mon, 18 Jun 2007 21:00:40 +0200, <t...@xxxxxxxxxxxxx> wrote:
In article <op.tt4oy5jift6h9m@xrousse>,
Jym <Jean-Yves.Moyen+n...@xxxxxxxxxxxx> wrote:
Typically, if one takes a graph with weight -1 on each edge and search
for
the shortest path between two vertices, why won't that gives an
Hamiltonian path ?
It will. However, the subtle point here is that the usual algorithms
that
people use for "shortest path" won't work. If you read the fine print,
you
will see that Dijkstra and Bellman-Ford, for example, won't work
properly in
this case. So it's probably misguided to think about the problem this
way;
one should just face up to the fact that the problem is qualitatively
different from shortest-path problems with nonnegative weights, and deal
with it head-on.
I still don't get it :-(
Bellman-Ford also works with negative weights, has long as there is no
cycle of negative weight (which will probably not be the case if all
weights are -1, of course).
Obviously, the original problem of the OP (finding longest path) is also
somewhat ill-defined if there are cycles (it will be +\infty).
Why won't Bellman-Ford algorithm work with all weights -1 (apart from
cycles) ?
It should work for longest path (in a graph without cycles).
I agree that there is a problem for finding "longest simple path" (ie
without taking the same edge several times). The OP had not make it clear
if that's really what he meant by "longest path".
--
Hypocoristiquement,
Jym.
Right, Bellman-Ford works in directed graphs with no negative cycles.
Note that if the graph is acyclic, you can compute shortest/longest
path in linear time via topological sort.
.
- Follow-Ups:
- Re: Finding longest path between two vertices
- From: tchow
- Re: Finding longest path between two vertices
- References:
- Finding longest path between two vertices
- From: Tim Frink
- Re: Finding longest path between two vertices
- From: Tim Frink
- Re: Finding longest path between two vertices
- From: Joachim Pimiskern
- Re: Finding longest path between two vertices
- From: Jym
- Re: Finding longest path between two vertices
- From: tchow
- Re: Finding longest path between two vertices
- From: Jym
- Finding longest path between two vertices
- Prev by Date: Re: Finding longest path between two vertices
- Next by Date: Re: Finding longest path between two vertices
- Previous by thread: Re: Finding longest path between two vertices
- Next by thread: Re: Finding longest path between two vertices
- Index(es):
Relevant Pages
|