All pairs shortest paths: Difference between revisions

From Algowiki
Jump to navigation Jump to search
Line 4: Line 4:
# An arc length <math>l(a) \in \mathbb{R}</math> for each arc <math>a \in A</math>
# An arc length <math>l(a) \in \mathbb{R}</math> for each arc <math>a \in A</math>


== Ouptut ==
== Output ==


For each pair <math>(v,w) \in A</math> with <math> v,w \in V</math>, the length <math>\Delta(v,w)</math> of a shortest <math>(v,w)</math>-path in <math>G</math> with respect to <math>l</math>.
For each pair <math>(v,w) \in A</math> with <math> v,w \in V</math>, the length <math>\Delta(v,w)</math> of a shortest <math>(v,w)</math>-path in <math>G</math> with respect to <math>\ell</math> among all paths that have at most <math>|V|</math> arcs.
 
'''Remark:'''
Obviously, a shortest path that contains no negative cycle is simple, so it has at most <math>|V|-1</math> arcs. If there are negative cycles, there are pairs <math>v,w\in V</math> for which the lengths of all <math>(v,w)</math> is unbounded from below. At least one of these paths runs exactly once through one simple negative cycle and For each such pair, there is a negative


== Complexity ==
== Complexity ==

Revision as of 07:41, 22 October 2014

Input

  1. A directed graph [math]\displaystyle{ G = (V,A) }[/math]
  2. An arc length [math]\displaystyle{ l(a) \in \mathbb{R} }[/math] for each arc [math]\displaystyle{ a \in A }[/math]

Output

For each pair [math]\displaystyle{ (v,w) \in A }[/math] with [math]\displaystyle{ v,w \in V }[/math], the length [math]\displaystyle{ \Delta(v,w) }[/math] of a shortest [math]\displaystyle{ (v,w) }[/math]-path in [math]\displaystyle{ G }[/math] with respect to [math]\displaystyle{ \ell }[/math] among all paths that have at most [math]\displaystyle{ |V| }[/math] arcs.

Remark: Obviously, a shortest path that contains no negative cycle is simple, so it has at most [math]\displaystyle{ |V|-1 }[/math] arcs. If there are negative cycles, there are pairs [math]\displaystyle{ v,w\in V }[/math] for which the lengths of all [math]\displaystyle{ (v,w) }[/math] is unbounded from below. At least one of these paths runs exactly once through one simple negative cycle and For each such pair, there is a negative

Complexity

Polynomial

Known algorithms

  1. Floyd-Warshall
  2. Bellman-Ford
  3. Shortest paths by repeated squaring (variant of Bellman-Ford)