All-Pairs Shortest Paths

Download Report

Transcript All-Pairs Shortest Paths

All-Pairs Shortest Paths &
Essential Subgraph
01/25/2005 Jinil Han
Problem Description

Finding shortest paths between all pairs of
vertices in a directed graph G=(V,E) with
nonnegative edge weights
n=|V|, m=|E|
Well-known Algorithms

Dijkstra’s algorithm
running a single-source shortest paths algorithm |V| times
O(n2lgn + nm), when implementing priority queue with a
Fibonacci heap
when all edge weights are nonnegative
** Fibonacci heap
delete-min : O(lgn)
priority change : O(1)
Well-known Algorithms

Bellman-Ford algorithm
dj(m+1) = min {dj(m), min {dk(m), +akj}}
O(n2m), O(n4) if graph is dense
negative edges are allowed

Floyd-Warshall algorithm
dij(k) = min {dij(k-1) , dik(k-1) + dkj(k-1)}
O(n3)
negative edges are allowed
Now, introduce two algorithms with running time of O(n2lgn+ns)
Algorithm Outline

Run Dijkstra’s single source algorithm in parallel for all points in
the graph

Discover the hidden “shortest path structure” (essential
subgraph H)

Running time is equivalent to solving n single-source shortest
path problems using only the edges in H
O(n2lgn + ns), s = the number of edges in H

s is likely to be small in practice, for general random graph,
s = O(nlgn) almost surely
 expected running time is O(n2lgn)
Hidden Paths Algorithm





Maintains a heap containing for each ordered pair of vertices u,
v the best path from u to v found so far
At each iteration, removes a path (u~v), from top of the heap
(this is the optimal path from u to v)
This path is now used to construct a set of new candidate
paths
If a new candidate path (w~t) is shorter, it replaces the current
best path from w to t in the heap
This maintains the optimality of the path at the top of the heap
Hidden Paths Algorithm
Hidden Paths Algorithm
Hidden Paths Algorithm

Example
Hidden Paths Algorithm

Running time analysis
1. the initialization step : a heap of size O(n2)
2. Step 1 & Step 2 : at most n(n-1) times
 at most n(n-1) delete-min operations
3. the only candidate paths created are those of the form
(u,v~w) where both (u,v) and (v~w) are optimal
 The total number of candidate paths created is O(sn)
 At most one priority change operation associated with each
candidate path
Hidden Path Algorithm

Running time analysis
SHORT Algorithm

Rather than iterating over nodes to solve n SSP problems, the
algorithm iterates over edges and solves the SSP problem
incrementally ( same as hidden Path algorithm)

It is efficient because each distance need only be computed
once

The two algorithms would discover and report distances in
different order

The n shortest-path trees are constructed as a by-product of
SHORT but not of Hidden Path algorithm
SHORT Algorithm

Essential subgraph
contain an edge (x,y) in E whenever d(x,y) =c(x,y) and there is
no alternate path of equivalent cost, that is, edge (x,y) is in H
when it is uniquely the shortest path in G between x and y
G
H
SHORT Algorithm

Think of SHORT as an algorithm for constructing H

SHORT builds H correctly (refer to a paper for proof)
SHORT Algorithm

The Search Procedure
returns a decision accept or reject depending on whether an
alternate path exists in the partially built subgraph Hi
construct n single-source trees incrementally
** review of Dijkstra’s algorithm
A shortest path tree T(v) rooted at v is built
maintain a heap of fringe vertices which are not in T(v) but are
adjacent to vertices in T(v)
vertices are extracted from the fringe heap and added to T(v)
Dijkstra-Process(v,x,y) operates on edge (x,y) when vertex x is
added to T(v)
SHORT Algorithm

The Search Procedure
SHORT Algorithm

Example
SHORT Algorithm

Running time analysis
for each vertex, Dijkstra-Process processes each edge of H
exactly once
at most n inserts, deletes, and s decrease-key operations on
the fringe heap  O(s + nlgn) using Fibonacci heaps
 The total cost is therefore O(n2lgn + ns)
s in a Random graph

To predict behavior of algorithms in practice
for a large class of probability distributions on random graph,
s= O(nlgn)
consider dist. F on nonnegative edge weights, which doesn’t
depend on n, such that F’(0) > 0 (Ex. Uniform and exponential)
Th. Let G be complete directed graph, whose edge weights are
chosen independently according to F. Then with probability 1O(n-1), the diameter of G is O(lgn/n), and hence s = O(nlgn)
 with high probability the running time of the algorithms are
O(n2lgn)
Essential Subgraph

The essential subgraph is unique and that for every pair of
vertices there is a shortest path between them comprising only
edges in H
 H is the optimal subgraph for distance computations on G

H is exactly the union of n SSP trees and H must contain a
minimum spanning tree of G