This preview shows pages 1–3. Sign up to view the full content.
All Pairs Shortest Paths
•
Let
G
= (
V,E
) be a directed graph with edge weights
c
uv
for each edge (
u,v
)
∈
E
.
•
Let
V
=
{
1
,
2
,
···
,n
}
and

E

=
m
.
•
Cost
c
(
p
) of a path
p
= (
v
0
,v
1
,...,v
k
) is
∑
k
i
=1
c
v
i

1
,v
i
.
•
Shortest path from
s
to
t
is a path with minimum cost among all paths from
s
to
t
.
•
Problem: ﬁnd a shortest path from vertex
i
to vertex
j
for all vertices 1
≤
i,j
≤
n
.
•
Need the following fact:
– FACT 1:
If
G
has no negative cycles then there is a shortest path from
i
to
j
with at most
n

1 edges.
•
Nonnegative edge weights: Dijkstra’s algorithm with each vertex as source. Time is
O
(
nm
log
n
)
with binary heap data structure.
•
Negative edge weights: BellmanFord algorithm with each vertex as source. Time is
O
(
n
2
m
).
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentAll Pairs Shortest Paths : Characterization
•
For any pair of vertices
i,j
∈
V
, let
P
k
ij
be a shortest path from
i
to
j
such that all intermediate
vertices (excludes
i
and
j
) along this path are from the set
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '10
 N/A

Click to edit the document details