Re: n edges shortest path
- From: "Per Vognsen" <per.vognsen@xxxxxxxxx>
- Date: 27 Apr 2005 22:05:17 -0700
Michal Brzozowski wrote:
> samipate@xxxxxxxxx wrote in message
news:<1114550264.734142.128090@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
> > Hello list
> >
> > Is there a well known algorithm that determines in an oriented
graph
> > the shortest path using exactly n edges ?
>
> hello
>
> One algorithm I can think of would be adding another axis to
> the vertices, so instead of 1..k they would be:
> (1,1) ... (k,1)
> (1,2) ... (k,2)
> .
> .
> .
> (1,n) ... (k,n)
>
> the second number in the pair would of course represent the number of
edges
> that you took to given vertex.
You forgot to specify the edges and weights of this graph. In the above
notation, (x,i) should be adjacent to (y,j) iff (1) x is adjacent to y
and (2) j = i+1. If (x,i) is adjacent to (y,j) then let the weight of
the edge equal the weight of the edge joining x to y.
Let s denote the source vertex. In the "associated graph", the length
of the shortest path from (s,0) to (x,i) corresponds to the length of
the shortest i-edge path from s to x. This is most easily proven in two
steps. First, show that there exists a path from (s,0) to (x,i) in the
associated graph iff there exists an i-edge path from s to x in the
original graph. Second, show that the length of any path from (s,0) to
(x,i) equals the length of the corresponding path in the original
graph.
If V and E are the vertex and edge sets of the original graph then the
associated graph has O(n*|V|) vertices and O(n*|E|) edges. If the
problem is solved using Dijkstra's algorithm you thus get a worst-case
runtime of O(n*(|V|+|E|)*log(|V|)). In other words, O(n) times more
work than the standard shortest path problem for the graph.
Another option is to use a dynamic programming algorithm. If d(x,i) is
the length of the shortest i-edge path from s to x then we have the
recurrence relations:
d(s,0) = 0
d(x,0) = infinity for any x != s
d(x,i+1) = min(y is adjacent to x){d(y,i) + w(x,y)}
(Here w(x,y) is the weight of the edge joining x and y.)
These relations give rise to a really simple dynamic programming
algorithm with a runtime complexity of O(n*u*|V|) where u is the
maximum outdegree of any vertex in the graph.
Per
.
- References:
- n edges shortest path
- From: samipate
- Re: n edges shortest path
- From: Michal Brzozowski
- n edges shortest path
- Prev by Date: Re: P=NP: Linear Programming Formulation of the TSP
- Next by Date: Re: Any solution to this problem?
- Previous by thread: Re: n edges shortest path
- Next by thread: Reply: Time dependent shortest path
- Index(es):
Relevant Pages
|