AllPairs Shortest Paths - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

AllPairs Shortest Paths

Description:

Properties of Interest ... The path from vr to vs must be minimal (or it wouldn't exist in the shortest path) ... vr. MIN. MINs. Growing Path Length ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 17
Provided by: jonapr
Category:

less

Transcript and Presenter's Notes

Title: AllPairs Shortest Paths


1
All-Pairs Shortest Paths
  • ITSD4312

2
Outline
  • Review of graph theory
  • Problem definition
  • Properties of interest
  • Recurrence
  • Example
  • Recent Work
  • References

3
Graph Terminology
  • G (V, E)
  • W weight matrix
  • wij weight/length of edge (vi, vj)
  • wij 8 if vi and vj are not connected by an edge
  • wii 0
  • Assume W has positive, 0, and negative values
  • For this problem, we cannot have a negative-sum
    cycle in G

4
Weighted Graph and Weight Matrix
v1
v0
5
-4
v2
3
1
2
7
9
6
v3
v4
5
Directed Weighted Graph and Weight Matrix
v3
v0
-2
1
7
v2
v1
-1
2
5
9
6
3
4
0 1 2 3 4 5
v4
v5
6
All-Pairs Shortest Paths Problem Defined
  • For every pair of vertices vi and vj in V, it is
    required to find the length of the shortest path
    from vi to vj along edges in E.
  • Specifically, a matrix D is to be constructed
    such that dij is the length of the shortest path
    from vi to vj in G, for all i and j.
  • Length of a path (or cycle) is the sum of the
    lengths (weights) of the edges forming it.

7
Sample Shortest Path
v3
v0
-2
1
7
v2
v1
2
-1
5
9
6
3
4
v4
v5
Shortest path from v0 to v4 is along edges (v0,
v1), (v1, v2), (v2, v4) and has length 6
8
Disallowing Negative-length Cycles
  • APSP does not allow for input to contain
    negative-length cycles
  • This is necessary because
  • If such a cycle were to exist within a path from
    vi to vj, then one could traverse this cycle
    indefinitely, producing paths of ever shorter
    lengths from vi to vj.
  • If a negative-length cycle exists, then all paths
    which contain this cycle would have a length of
    -8.

9
Properties of Interest
  • Let denote the length of the shortest path
    from vi to vj that goes through at most k - 1
    intermediate vertices (k hops)
  • wij (edge length from vi to vj)
  • If i ? j and there is no edge from vi to vj, then
  • Also,
  • Given that there are no negative weighted cycles
    in G, there is no advantage in visiting any
    vertex more than once in the shortest path from
    vi to vj.
  • Since there are only n vertices in G,

10
Guaranteeing Shortest Paths
  • If the shortest path from vi to vj contains vr
    and vs (where vr precedes vs)
  • The path from vr to vs must be minimal (or it
    wouldnt exist in the shortest path)
  • Thus, to obtain the shortest path from vi to vj,
    we can compute all combinations of optimal
    sub-paths (whose concatenation is a path from vi
    to vj), and then select the shortest one

vi
vs
vj
vr
MIN
MIN
MIN
? MINs
11
Growing Path Length
  • Iteratively build longer paths (similar to
    Dijkstras algorithm for single-source shortest
    path)
  • From 0 to v-1 lengths
  • Runs in O(v4)

12
Recurrence Definition
  • For k gt 1,
  • Guarantees O(log k) steps to calculate
  • Improves to O(v3 lg v)

13
Floyd Worshall
  • Let Dk matrix with entries dij for paths among
    vertices v1, v2, , vk.
  • D0 W
  • Since we arent allowing any intermediate
    vertices (k0), dij ? i and j wij

14
Example
0 1 2 3 4
D0 Wjk
v1
3
4
8
v2
7
v0
1
-5
-4
2
6
v3
v4
15
Recent Work on Sequential Algorithms
  • Floyd-Warshall algorithm is T(V3)
  • Appropriate for dense graphs E O(V2)
  • Johnsons algorithm
  • Appropriate for sparse graphs E O(V)
  • O(V2 log V V E) if using a Fibonacci heap
  • O(V E log V) if using binary min-heap
  • Shoshan and Zwick (1999)
  • Integer edge weights in 1, 2, , W
  • O(W V? p(V W)) where ? 2.376 and p is a polylog
    function
  • Pettie (2002)
  • Allows real-weighted edges
  • O(V2 log log V V E)

Strassens Algorithm (matrix multiplication)
16
References
  • Akl S. G. Parallel Computation Models and
    Methods. Prentice Hall, Upper Saddle River NJ,
    pp. 381-384,1997.
  • Cormen T. H., Leiserson C. E., Rivest R. L., and
    Stein C. Introduction to Algorithms (2nd
    Edition). The MIT Press, Cambridge MA, pp.
    620-642, 2001.
Write a Comment
User Comments (0)
About PowerShow.com