SlideShare a Scribd company logo
1 of 437
Download to read offline
Data Structures and Algorithms – COMS21103
Shortest Paths Revisited
Negative Weights and All-Pairs
Benjamin Sach
inspired by slides by Ashley Montanaro
In today’s lectures we’ll be revisiting the shortest paths problem
In particular we’ll be interested in algorithms which allow negative edge weights
in a weighted, directed graph. . .
The shortest path from MVB to Temple Meads
(according to Google Maps)
and algorithms which compute the shortest path between all pairs of vertices
Part one
Single Source Shortest Paths with negative weights
Single source shortest paths with negative weights
in a weighted, directed graph. . .
Bellman-Ford’s algorithm solves the single source shortest paths problem
-21
2
1
1 2 4
3
1
2
-1
A
B E
D
C F
G
Single source shortest paths with negative weights
in a weighted, directed graph. . .
Bellman-Ford’s algorithm solves the single source shortest paths problem
It finds the shortest path from
a given source vertex
to every other vertex
-21
2
1
1 2 4
3
1
2
-1
A
B E
D
C F
G
Single source shortest paths with negative weights
in a weighted, directed graph. . .
Bellman-Ford’s algorithm solves the single source shortest paths problem
It finds the shortest path from
a given source vertex
The weights are allowed to be
to every other vertex
positive or negative
-21
2
1
1 2 4
3
1
2
-1
A
B E
D
C F
G
Single source shortest paths with negative weights
in a weighted, directed graph. . .
Bellman-Ford’s algorithm solves the single source shortest paths problem
It finds the shortest path from
a given source vertex
The weights are allowed to be
to every other vertex
The graph is stored as an Adjacency List
positive or negative
-21
2
1
1 2 4
3
1
2
-1
A
B E
D
C F
G
Single source shortest paths with negative weights
in a weighted, directed graph. . .
Bellman-Ford’s algorithm solves the single source shortest paths problem
It finds the shortest path from
a given source vertex
The weights are allowed to be
to every other vertex
We will not need any
non-elementary data structures
The graph is stored as an Adjacency List
positive or negative
-21
2
1
1 2 4
3
1
2
-1
A
B E
D
C F
G
Single source shortest paths with negative weights
in a weighted, directed graph. . .
Bellman-Ford’s algorithm solves the single source shortest paths problem
It finds the shortest path from
a given source vertex
The weights are allowed to be
to every other vertex
We will not need any
non-elementary data structures
Previously we saw that Dijkstra’s algorithm (implemented with a binary heap) solves this
problem in O((|V | + |E|) log |V |) time when the edges have non-negative weights
|V | is the number of vertices and |E| is the number of edges
The graph is stored as an Adjacency List
positive or negative
-21
2
1
1 2 4
3
1
2
-1
A
B E
D
C F
G
Negative weight cycles
If some of the edges in the graph have negative weights
the idea of a shortest path might not make sense:
If there is a path from s to t which includes a negative weight cycle,
A X
Z
Y B
What is the shortest path from A to B?
(-1)
1 1 1
A negative weight cycle is a path from a vertex v back to v such that
the sum of the edge weights is negative
there is no shortest path from s to t
A X
Z
Y B
-1 -1
1 1 1
Negative weight cycles
If some of the edges in the graph have negative weights
the idea of a shortest path might not make sense:
If there is a path from s to t which includes a negative weight cycle,
A X
Z
Y B
What is the shortest path from A to B?
(-1)
1 1 1
A negative weight cycle is a path from a vertex v back to v such that
the sum of the edge weights is negative
there is no shortest path from s to t
We will first discuss a (slightly) simpler version of Bellman-Ford
that assumes there are no such cycles
A X
Z
Y B
-1 -1
1 1 1
Most of the Bellman-Ford algorithm
MOSTOFBELLMAN-FORD(s)
weight(u, v) is the weight of
the edge from u to v
(u, v) ∈ E iff there is an
edge from u to v
dist(v) is the length of the shortest
path between s and v, found so far
For all v, set dist(v) = ∞
set dist(s) = 0
For i = 1, 2, . . . , |V |,
For every edge (u, v) ∈ E
If dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
Most of the Bellman-Ford algorithm
MOSTOFBELLMAN-FORD(s)
weight(u, v) is the weight of
the edge from u to v
(u, v) ∈ E iff there is an
edge from u to v
dist(v) is the length of the shortest
path between s and v, found so far
For all v, set dist(v) = ∞
set dist(s) = 0
For i = 1, 2, . . . , |V |,
For every edge (u, v) ∈ E
If dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
The algorithm repeatedly asks, for each edge (u, v)
“can I find a shorter route to v if I go via u?”
Most of the Bellman-Ford algorithm
MOSTOFBELLMAN-FORD(s)
weight(u, v) is the weight of
the edge from u to v
(u, v) ∈ E iff there is an
edge from u to v
dist(v) is the length of the shortest
path between s and v, found so far
For all v, set dist(v) = ∞
set dist(s) = 0
For i = 1, 2, . . . , |V |,
For every edge (u, v) ∈ E
If dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
s
u
v
The algorithm repeatedly asks, for each edge (u, v)
“can I find a shorter route to v if I go via u?”
Most of the Bellman-Ford algorithm
MOSTOFBELLMAN-FORD(s)
weight(u, v) is the weight of
the edge from u to v
(u, v) ∈ E iff there is an
edge from u to v
dist(v) is the length of the shortest
path between s and v, found so far
For all v, set dist(v) = ∞
set dist(s) = 0
For i = 1, 2, . . . , |V |,
For every edge (u, v) ∈ E
If dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
This is called RELAXING edge (u, v)
s
u
v
The algorithm repeatedly asks, for each edge (u, v)
“can I find a shorter route to v if I go via u?”
Most of the Bellman-Ford algorithm
MOSTOFBELLMAN-FORD(s)
for each vertex v, dist(v) is the length of the shortest path between s and v
Claim When the MOSTOFBELLMAN-FORD algorithm terminates,
weight(u, v) is the weight of
the edge from u to v
(u, v) ∈ E iff there is an
edge from u to v
dist(v) is the length of the shortest
path between s and v, found so far
For all v, set dist(v) = ∞
set dist(s) = 0
For i = 1, 2, . . . , |V |,
For every edge (u, v) ∈ E
If dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
(assuming there are no-negative weight cycles)
This is called RELAXING edge (u, v)
s
u
v
The algorithm repeatedly asks, for each edge (u, v)
“can I find a shorter route to v if I go via u?”
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
We start by setting dist(s) = 0 and every other dist(v) = ∞. . .
- the length of the best path
between s and v, found so far
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
∞ > 0 + (−1)
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
∞ > 0 + (−1)
-1
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
∞ > 0 + 1
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0 ∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
∞ > 0 + 1
1
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0 ∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0 ∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1
−1 < 1 + 1
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0 ∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1
−1 < 1 + 1
(so we don’t change dist)
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0 ∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0 ∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1
∞ > 1 + 3
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1
∞ > 1 + 3
4
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
−1 < ∞ + 2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
−1 < ∞ + 2
(so we don’t change dist)
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
∞ < ∞ + 2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
∞ < ∞ + 2 (dist is still ∞)
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0 ∞
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
∞ > −1 + (−2)
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
∞ > −1 + (−2)
-3
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
-3
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
-3
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
-3
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
-3
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
-3
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
-3
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
1 4
-3
1 > −3 + 1
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
1 > −3 + 1
-2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞ ∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
We now start iteration 1. . .
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
This is the end of iteration 1
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
this looks good
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
so does this
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
this doesn’t look so good
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
neither does this
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
neither does this
(it’s not the shortest path length)
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
neither does this
(it’s not the shortest path length)
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
neither does this
(it’s not the shortest path length)
This path has length −1
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
we aren’t done
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
but it seems like we made progresswe aren’t done
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
but it seems like we made progresswe aren’t done
does every iteration make progress?
RELAX(u,v)
if dist(v) > dist(u) + weight(u, v)
dist(v) = dist(u) + weight(u, v)
In each iteration we RELAX every edge (u, v)
MOSTOFBELLMAN-FORD runs |V | iterations,
dist(v)
37 vertex v
s
(in the order they occur in the adjacency list)
0
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
We’re going to simulate
MOSTOFBELLMAN-FORD(s)
- the length of the best path
between s and v, found so far
-1
4
-3
-2
-2
2
How are things looking?
but it seems like we made progresswe aren’t done
does every iteration make progress?
are |V | iterations enough?
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
Iteration 1:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
Iteration 1:
“relax this”
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
Iteration 1:
“relax this”
-1
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
Iteration 1:
-1
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
Iteration 2:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
Iteration 2:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
Iteration 2:
“relax this”
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
Iteration 2:
“relax this”
-3
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
Iteration 2:
-3
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
Iteration 3:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
Iteration 3:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
“relax this”
Iteration 3:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
“relax this”
-2
Iteration 3:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
Iteration 3:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
Iteration 4:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
Iteration 4:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
“relax this”
Iteration 4:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
“relax this”
-1
Iteration 4:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
Iteration 4:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
Iteration 5:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
Iteration 5:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
“relax this”
Iteration 5:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
“relax this”
0
Iteration 5:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
0
Iteration 5:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
0
Iteration 6:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
0
Iteration 6:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
0
“relax this”
Iteration 6:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
0
“relax this”
-1
Iteration 6:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
t
This is a shortest path from s to t
-1
-3
-2
-1
0
-1
Iteration 6:
The proof idea
Imagine a different algorithm where in each iteration. . .
s
0
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
∞
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you only relax one edge (rather than all edges)
Further, imagine that (magically or otherwise), the edge that you relax in iteration i
is the i-th edge in a shortest path from s to some vertex t
When this algorithm terminates. . .
dist(t) is the length of the shortest path from s to t
t
This is a shortest path from s to t
-1
-3
-2
-1
0
-1
Iteration 6:
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
t
Consider the same
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
we relax this
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
at some point
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
we relax this
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
at some point
Don’t worry about what ? was before. RELAX picks the smaller of
? and 0 + (−1) so. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
we relax this
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
at some point
Don’t worry about what ? was before. RELAX picks the smaller of
? and 0 + (−1) so. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
Iteration 1:
-1
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
relax this
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
relax this
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 2:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
relax this
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
relax this
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 3:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
relax this
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
relax this
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 4:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
relax this
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
relax this
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 5:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
The proof idea
Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . .
s
0
?
?
?
?
?
?
?
?
?
?
?
3
1
1
1
4
-2
2
2
-2
-1
1
1
-1
1
3 -1
-1
2
1
-2
1
you relax every edge (rather than one edge)
At some point in iteration i
t
-1
Iteration 6:
Consider the same
you relax the i-th edge in the shortest path from s to t. . .
shortest path from s to t
-3
-2
-1
0
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs

More Related Content

What's hot

Is ellipse really a section of cone
Is ellipse really a section of coneIs ellipse really a section of cone
Is ellipse really a section of conenarayana dash
 
Structur e very helpfull
Structur e very helpfullStructur e very helpfull
Structur e very helpfullPrionath Roy
 
Jawaban soal-latihan1mekanika
Jawaban soal-latihan1mekanikaJawaban soal-latihan1mekanika
Jawaban soal-latihan1mekanikamiranteogbonna
 
Dynamics slideshare
Dynamics slideshareDynamics slideshare
Dynamics slideshareMalarMohana
 
Fundamentals of Physics (MOTION ALONG A STRAIGHT LINE)
Fundamentals of Physics (MOTION ALONG A STRAIGHT LINE)Fundamentals of Physics (MOTION ALONG A STRAIGHT LINE)
Fundamentals of Physics (MOTION ALONG A STRAIGHT LINE)Muhammad Faizan Musa
 
Solutions manual for engineering mechanics dynamics 13th edition by hibbeler
Solutions manual for engineering mechanics dynamics 13th edition by hibbelerSolutions manual for engineering mechanics dynamics 13th edition by hibbeler
Solutions manual for engineering mechanics dynamics 13th edition by hibbelertable3252
 
5 cramer-rao lower bound
5 cramer-rao lower bound5 cramer-rao lower bound
5 cramer-rao lower boundSolo Hermelin
 
Nonlinear Structural Dynamics: The Fundamentals Tutorial
Nonlinear Structural Dynamics: The Fundamentals TutorialNonlinear Structural Dynamics: The Fundamentals Tutorial
Nonlinear Structural Dynamics: The Fundamentals TutorialVanderbiltLASIR
 

What's hot (14)

S curve
S curveS curve
S curve
 
Transmission Line
Transmission LineTransmission Line
Transmission Line
 
Is ellipse really a section of cone
Is ellipse really a section of coneIs ellipse really a section of cone
Is ellipse really a section of cone
 
Structur e very helpfull
Structur e very helpfullStructur e very helpfull
Structur e very helpfull
 
481 lecture10
481 lecture10481 lecture10
481 lecture10
 
Jawaban soal-latihan1mekanika
Jawaban soal-latihan1mekanikaJawaban soal-latihan1mekanika
Jawaban soal-latihan1mekanika
 
Dynamics slideshare
Dynamics slideshareDynamics slideshare
Dynamics slideshare
 
Complex strains (2nd year)
Complex strains (2nd year)Complex strains (2nd year)
Complex strains (2nd year)
 
Fundamentals of Physics "VECTORS"
Fundamentals of Physics "VECTORS"Fundamentals of Physics "VECTORS"
Fundamentals of Physics "VECTORS"
 
Algebra-taller2
Algebra-taller2Algebra-taller2
Algebra-taller2
 
Fundamentals of Physics (MOTION ALONG A STRAIGHT LINE)
Fundamentals of Physics (MOTION ALONG A STRAIGHT LINE)Fundamentals of Physics (MOTION ALONG A STRAIGHT LINE)
Fundamentals of Physics (MOTION ALONG A STRAIGHT LINE)
 
Solutions manual for engineering mechanics dynamics 13th edition by hibbeler
Solutions manual for engineering mechanics dynamics 13th edition by hibbelerSolutions manual for engineering mechanics dynamics 13th edition by hibbeler
Solutions manual for engineering mechanics dynamics 13th edition by hibbeler
 
5 cramer-rao lower bound
5 cramer-rao lower bound5 cramer-rao lower bound
5 cramer-rao lower bound
 
Nonlinear Structural Dynamics: The Fundamentals Tutorial
Nonlinear Structural Dynamics: The Fundamentals TutorialNonlinear Structural Dynamics: The Fundamentals Tutorial
Nonlinear Structural Dynamics: The Fundamentals Tutorial
 

Viewers also liked

Pattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatchesPattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatchesBenjamin Sach
 
Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)Benjamin Sach
 
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's AlgorithmShortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's AlgorithmBenjamin Sach
 
Approximation Algorithms Part One: Constant factor approximations
Approximation Algorithms Part One: Constant factor approximationsApproximation Algorithms Part One: Constant factor approximations
Approximation Algorithms Part One: Constant factor approximationsBenjamin Sach
 
Hashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingHashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingBenjamin Sach
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First SearchBenjamin Sach
 
Range Minimum Queries
Range Minimum QueriesRange Minimum Queries
Range Minimum QueriesBenjamin Sach
 
Approximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximationsApproximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximationsBenjamin Sach
 
Pattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix ArraysPattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix ArraysBenjamin Sach
 
Lowest Common Ancestor
Lowest Common AncestorLowest Common Ancestor
Lowest Common AncestorBenjamin Sach
 
Approximation Algorithms Part Three: (F)PTAS
Approximation Algorithms Part Three: (F)PTASApproximation Algorithms Part Three: (F)PTAS
Approximation Algorithms Part Three: (F)PTASBenjamin Sach
 
Pattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix TreesPattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix TreesBenjamin Sach
 
Pattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming DistancePattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming DistanceBenjamin Sach
 

Viewers also liked (16)

Pattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatchesPattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatches
 
Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)
 
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's AlgorithmShortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
 
Approximation Algorithms Part One: Constant factor approximations
Approximation Algorithms Part One: Constant factor approximationsApproximation Algorithms Part One: Constant factor approximations
Approximation Algorithms Part One: Constant factor approximations
 
Hashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingHashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo Hashing
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
 
Range Minimum Queries
Range Minimum QueriesRange Minimum Queries
Range Minimum Queries
 
Approximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximationsApproximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximations
 
Pattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix ArraysPattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix Arrays
 
Lowest Common Ancestor
Lowest Common AncestorLowest Common Ancestor
Lowest Common Ancestor
 
Approximation Algorithms Part Three: (F)PTAS
Approximation Algorithms Part Three: (F)PTASApproximation Algorithms Part Three: (F)PTAS
Approximation Algorithms Part Three: (F)PTAS
 
Bloom Filters
Bloom FiltersBloom Filters
Bloom Filters
 
Pattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix TreesPattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix Trees
 
van Emde Boas trees
van Emde Boas treesvan Emde Boas trees
van Emde Boas trees
 
Pattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming DistancePattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming Distance
 
Probability Recap
Probability RecapProbability Recap
Probability Recap
 

Similar to Shortest Paths Part 2: Negative Weights and All-pairs

Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10Traian Rebedea
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithmRuchika Sinha
 
Bellman ford
Bellman fordBellman ford
Bellman fordKiran K
 
shortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdfshortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdfzefergaming
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithmsana younas
 
Inroduction_To_Algorithms_Lect14
Inroduction_To_Algorithms_Lect14Inroduction_To_Algorithms_Lect14
Inroduction_To_Algorithms_Lect14Naor Ami
 
lecture 21
lecture 21lecture 21
lecture 21sajinsc
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithmtaimurkhan803
 
SINGLE SOURCE SHORTEST PATH.ppt
SINGLE SOURCE SHORTEST PATH.pptSINGLE SOURCE SHORTEST PATH.ppt
SINGLE SOURCE SHORTEST PATH.pptshanthishyam
 
Single source shortes path in dag
Single source shortes path in dagSingle source shortes path in dag
Single source shortes path in dagKiran K
 
bellman-ford Theorem.ppt
bellman-ford Theorem.pptbellman-ford Theorem.ppt
bellman-ford Theorem.pptSaimaShaheen14
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraRoshan Tailor
 
Bellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraqBellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraqmontaser185
 

Similar to Shortest Paths Part 2: Negative Weights and All-pairs (20)

Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10
 
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Bellman ford
Bellman fordBellman ford
Bellman ford
 
shortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdfshortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdf
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
 
Inroduction_To_Algorithms_Lect14
Inroduction_To_Algorithms_Lect14Inroduction_To_Algorithms_Lect14
Inroduction_To_Algorithms_Lect14
 
lecture 21
lecture 21lecture 21
lecture 21
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithm
 
Chapter 25 aoa
Chapter 25 aoaChapter 25 aoa
Chapter 25 aoa
 
Chapter 26 aoa
Chapter 26 aoaChapter 26 aoa
Chapter 26 aoa
 
chapter24.ppt
chapter24.pptchapter24.ppt
chapter24.ppt
 
SINGLE SOURCE SHORTEST PATH.ppt
SINGLE SOURCE SHORTEST PATH.pptSINGLE SOURCE SHORTEST PATH.ppt
SINGLE SOURCE SHORTEST PATH.ppt
 
Single source shortes path in dag
Single source shortes path in dagSingle source shortes path in dag
Single source shortes path in dag
 
bellman-ford Theorem.ppt
bellman-ford Theorem.pptbellman-ford Theorem.ppt
bellman-ford Theorem.ppt
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstra
 
20 Single Source Shorthest Path
20 Single Source Shorthest Path20 Single Source Shorthest Path
20 Single Source Shorthest Path
 
19-graph1 (1).ppt
19-graph1 (1).ppt19-graph1 (1).ppt
19-graph1 (1).ppt
 
Shortest path
Shortest pathShortest path
Shortest path
 
Bellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraqBellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraq
 

More from Benjamin Sach

Approximation Algorithms Part Four: APTAS
Approximation Algorithms Part Four: APTASApproximation Algorithms Part Four: APTAS
Approximation Algorithms Part Four: APTASBenjamin Sach
 
Orthogonal Range Searching
Orthogonal Range SearchingOrthogonal Range Searching
Orthogonal Range SearchingBenjamin Sach
 
Hashing Part Two: Static Perfect Hashing
Hashing Part Two: Static Perfect HashingHashing Part Two: Static Perfect Hashing
Hashing Part Two: Static Perfect HashingBenjamin Sach
 
Line Segment Intersections
Line Segment IntersectionsLine Segment Intersections
Line Segment IntersectionsBenjamin Sach
 
Self-balancing Trees and Skip Lists
Self-balancing Trees and Skip ListsSelf-balancing Trees and Skip Lists
Self-balancing Trees and Skip ListsBenjamin Sach
 

More from Benjamin Sach (7)

Approximation Algorithms Part Four: APTAS
Approximation Algorithms Part Four: APTASApproximation Algorithms Part Four: APTAS
Approximation Algorithms Part Four: APTAS
 
Orthogonal Range Searching
Orthogonal Range SearchingOrthogonal Range Searching
Orthogonal Range Searching
 
Hashing Part Two: Static Perfect Hashing
Hashing Part Two: Static Perfect HashingHashing Part Two: Static Perfect Hashing
Hashing Part Two: Static Perfect Hashing
 
Hashing Part One
Hashing Part OneHashing Part One
Hashing Part One
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
 
Line Segment Intersections
Line Segment IntersectionsLine Segment Intersections
Line Segment Intersections
 
Self-balancing Trees and Skip Lists
Self-balancing Trees and Skip ListsSelf-balancing Trees and Skip Lists
Self-balancing Trees and Skip Lists
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 

Shortest Paths Part 2: Negative Weights and All-pairs

  • 1. Data Structures and Algorithms – COMS21103 Shortest Paths Revisited Negative Weights and All-Pairs Benjamin Sach inspired by slides by Ashley Montanaro
  • 2. In today’s lectures we’ll be revisiting the shortest paths problem In particular we’ll be interested in algorithms which allow negative edge weights in a weighted, directed graph. . . The shortest path from MVB to Temple Meads (according to Google Maps) and algorithms which compute the shortest path between all pairs of vertices
  • 3. Part one Single Source Shortest Paths with negative weights
  • 4. Single source shortest paths with negative weights in a weighted, directed graph. . . Bellman-Ford’s algorithm solves the single source shortest paths problem -21 2 1 1 2 4 3 1 2 -1 A B E D C F G
  • 5. Single source shortest paths with negative weights in a weighted, directed graph. . . Bellman-Ford’s algorithm solves the single source shortest paths problem It finds the shortest path from a given source vertex to every other vertex -21 2 1 1 2 4 3 1 2 -1 A B E D C F G
  • 6. Single source shortest paths with negative weights in a weighted, directed graph. . . Bellman-Ford’s algorithm solves the single source shortest paths problem It finds the shortest path from a given source vertex The weights are allowed to be to every other vertex positive or negative -21 2 1 1 2 4 3 1 2 -1 A B E D C F G
  • 7. Single source shortest paths with negative weights in a weighted, directed graph. . . Bellman-Ford’s algorithm solves the single source shortest paths problem It finds the shortest path from a given source vertex The weights are allowed to be to every other vertex The graph is stored as an Adjacency List positive or negative -21 2 1 1 2 4 3 1 2 -1 A B E D C F G
  • 8. Single source shortest paths with negative weights in a weighted, directed graph. . . Bellman-Ford’s algorithm solves the single source shortest paths problem It finds the shortest path from a given source vertex The weights are allowed to be to every other vertex We will not need any non-elementary data structures The graph is stored as an Adjacency List positive or negative -21 2 1 1 2 4 3 1 2 -1 A B E D C F G
  • 9. Single source shortest paths with negative weights in a weighted, directed graph. . . Bellman-Ford’s algorithm solves the single source shortest paths problem It finds the shortest path from a given source vertex The weights are allowed to be to every other vertex We will not need any non-elementary data structures Previously we saw that Dijkstra’s algorithm (implemented with a binary heap) solves this problem in O((|V | + |E|) log |V |) time when the edges have non-negative weights |V | is the number of vertices and |E| is the number of edges The graph is stored as an Adjacency List positive or negative -21 2 1 1 2 4 3 1 2 -1 A B E D C F G
  • 10. Negative weight cycles If some of the edges in the graph have negative weights the idea of a shortest path might not make sense: If there is a path from s to t which includes a negative weight cycle, A X Z Y B What is the shortest path from A to B? (-1) 1 1 1 A negative weight cycle is a path from a vertex v back to v such that the sum of the edge weights is negative there is no shortest path from s to t A X Z Y B -1 -1 1 1 1
  • 11. Negative weight cycles If some of the edges in the graph have negative weights the idea of a shortest path might not make sense: If there is a path from s to t which includes a negative weight cycle, A X Z Y B What is the shortest path from A to B? (-1) 1 1 1 A negative weight cycle is a path from a vertex v back to v such that the sum of the edge weights is negative there is no shortest path from s to t We will first discuss a (slightly) simpler version of Bellman-Ford that assumes there are no such cycles A X Z Y B -1 -1 1 1 1
  • 12. Most of the Bellman-Ford algorithm MOSTOFBELLMAN-FORD(s) weight(u, v) is the weight of the edge from u to v (u, v) ∈ E iff there is an edge from u to v dist(v) is the length of the shortest path between s and v, found so far For all v, set dist(v) = ∞ set dist(s) = 0 For i = 1, 2, . . . , |V |, For every edge (u, v) ∈ E If dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v)
  • 13. Most of the Bellman-Ford algorithm MOSTOFBELLMAN-FORD(s) weight(u, v) is the weight of the edge from u to v (u, v) ∈ E iff there is an edge from u to v dist(v) is the length of the shortest path between s and v, found so far For all v, set dist(v) = ∞ set dist(s) = 0 For i = 1, 2, . . . , |V |, For every edge (u, v) ∈ E If dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) The algorithm repeatedly asks, for each edge (u, v) “can I find a shorter route to v if I go via u?”
  • 14. Most of the Bellman-Ford algorithm MOSTOFBELLMAN-FORD(s) weight(u, v) is the weight of the edge from u to v (u, v) ∈ E iff there is an edge from u to v dist(v) is the length of the shortest path between s and v, found so far For all v, set dist(v) = ∞ set dist(s) = 0 For i = 1, 2, . . . , |V |, For every edge (u, v) ∈ E If dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) s u v The algorithm repeatedly asks, for each edge (u, v) “can I find a shorter route to v if I go via u?”
  • 15. Most of the Bellman-Ford algorithm MOSTOFBELLMAN-FORD(s) weight(u, v) is the weight of the edge from u to v (u, v) ∈ E iff there is an edge from u to v dist(v) is the length of the shortest path between s and v, found so far For all v, set dist(v) = ∞ set dist(s) = 0 For i = 1, 2, . . . , |V |, For every edge (u, v) ∈ E If dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) This is called RELAXING edge (u, v) s u v The algorithm repeatedly asks, for each edge (u, v) “can I find a shorter route to v if I go via u?”
  • 16. Most of the Bellman-Ford algorithm MOSTOFBELLMAN-FORD(s) for each vertex v, dist(v) is the length of the shortest path between s and v Claim When the MOSTOFBELLMAN-FORD algorithm terminates, weight(u, v) is the weight of the edge from u to v (u, v) ∈ E iff there is an edge from u to v dist(v) is the length of the shortest path between s and v, found so far For all v, set dist(v) = ∞ set dist(s) = 0 For i = 1, 2, . . . , |V |, For every edge (u, v) ∈ E If dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) (assuming there are no-negative weight cycles) This is called RELAXING edge (u, v) s u v The algorithm repeatedly asks, for each edge (u, v) “can I find a shorter route to v if I go via u?”
  • 17. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far
  • 18. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) We start by setting dist(s) = 0 and every other dist(v) = ∞. . . - the length of the best path between s and v, found so far
  • 19. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far
  • 20. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far We now start iteration 1. . .
  • 21. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far We now start iteration 1. . .
  • 22. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far ∞ > 0 + (−1) We now start iteration 1. . .
  • 23. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far ∞ > 0 + (−1) -1 We now start iteration 1. . .
  • 24. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 We now start iteration 1. . .
  • 25. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 ∞ > 0 + 1 We now start iteration 1. . .
  • 26. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 ∞ > 0 + 1 1 We now start iteration 1. . .
  • 27. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 We now start iteration 1. . .
  • 28. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 −1 < 1 + 1 We now start iteration 1. . .
  • 29. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 −1 < 1 + 1 (so we don’t change dist) We now start iteration 1. . .
  • 30. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 We now start iteration 1. . .
  • 31. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 ∞ > 1 + 3 We now start iteration 1. . .
  • 32. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 ∞ > 1 + 3 4 We now start iteration 1. . .
  • 33. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 We now start iteration 1. . .
  • 34. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 We now start iteration 1. . .
  • 35. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 −1 < ∞ + 2 We now start iteration 1. . .
  • 36. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 −1 < ∞ + 2 (so we don’t change dist) We now start iteration 1. . .
  • 37. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 We now start iteration 1. . .
  • 38. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 ∞ < ∞ + 2 We now start iteration 1. . .
  • 39. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 ∞ < ∞ + 2 (dist is still ∞) We now start iteration 1. . .
  • 40. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 We now start iteration 1. . .
  • 41. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 ∞ > −1 + (−2) We now start iteration 1. . .
  • 42. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 ∞ > −1 + (−2) -3 We now start iteration 1. . .
  • 43. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 -3 We now start iteration 1. . .
  • 44. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 -3 We now start iteration 1. . .
  • 45. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 -3 We now start iteration 1. . .
  • 46. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 -3 We now start iteration 1. . .
  • 47. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 -3 We now start iteration 1. . .
  • 48. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 -3 We now start iteration 1. . .
  • 49. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 1 4 -3 1 > −3 + 1 We now start iteration 1. . .
  • 50. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 1 > −3 + 1 -2 We now start iteration 1. . .
  • 51. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 We now start iteration 1. . .
  • 52. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 We now start iteration 1. . .
  • 53. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 We now start iteration 1. . .
  • 54. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 We now start iteration 1. . .
  • 55. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 We now start iteration 1. . .
  • 56. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 We now start iteration 1. . .
  • 57. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 We now start iteration 1. . .
  • 58. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 We now start iteration 1. . .
  • 59. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 We now start iteration 1. . .
  • 60. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 We now start iteration 1. . .
  • 61. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 We now start iteration 1. . .
  • 62. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 This is the end of iteration 1
  • 63. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2
  • 64. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking?
  • 65. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? this looks good
  • 66. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? so does this
  • 67. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? this doesn’t look so good
  • 68. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? neither does this
  • 69. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? neither does this (it’s not the shortest path length)
  • 70. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? neither does this (it’s not the shortest path length)
  • 71. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? neither does this (it’s not the shortest path length) This path has length −1
  • 72. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking?
  • 73. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? we aren’t done
  • 74. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? but it seems like we made progresswe aren’t done
  • 75. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? but it seems like we made progresswe aren’t done does every iteration make progress?
  • 76. RELAX(u,v) if dist(v) > dist(u) + weight(u, v) dist(v) = dist(u) + weight(u, v) In each iteration we RELAX every edge (u, v) MOSTOFBELLMAN-FORD runs |V | iterations, dist(v) 37 vertex v s (in the order they occur in the adjacency list) 0 ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 We’re going to simulate MOSTOFBELLMAN-FORD(s) - the length of the best path between s and v, found so far -1 4 -3 -2 -2 2 How are things looking? but it seems like we made progresswe aren’t done does every iteration make progress? are |V | iterations enough?
  • 77. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges)
  • 78. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t
  • 79. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t
  • 80. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t Iteration 1:
  • 81. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t Iteration 1: “relax this”
  • 82. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t Iteration 1: “relax this” -1
  • 83. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t Iteration 1: -1
  • 84. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 Iteration 2:
  • 85. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 Iteration 2:
  • 86. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 Iteration 2: “relax this”
  • 87. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 Iteration 2: “relax this” -3
  • 88. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 Iteration 2: -3
  • 89. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 Iteration 3:
  • 90. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 Iteration 3:
  • 91. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 “relax this” Iteration 3:
  • 92. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 “relax this” -2 Iteration 3:
  • 93. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 Iteration 3:
  • 94. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 Iteration 4:
  • 95. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 Iteration 4:
  • 96. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 “relax this” Iteration 4:
  • 97. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 “relax this” -1 Iteration 4:
  • 98. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 Iteration 4:
  • 99. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 Iteration 5:
  • 100. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 Iteration 5:
  • 101. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 “relax this” Iteration 5:
  • 102. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 “relax this” 0 Iteration 5:
  • 103. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 0 Iteration 5:
  • 104. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 0 Iteration 6:
  • 105. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 0 Iteration 6:
  • 106. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 0 “relax this” Iteration 6:
  • 107. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 0 “relax this” -1 Iteration 6:
  • 108. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t t This is a shortest path from s to t -1 -3 -2 -1 0 -1 Iteration 6:
  • 109. The proof idea Imagine a different algorithm where in each iteration. . . s 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you only relax one edge (rather than all edges) Further, imagine that (magically or otherwise), the edge that you relax in iteration i is the i-th edge in a shortest path from s to some vertex t When this algorithm terminates. . . dist(t) is the length of the shortest path from s to t t This is a shortest path from s to t -1 -3 -2 -1 0 -1 Iteration 6:
  • 110. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge)
  • 111. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) t Consider the same shortest path from s to t
  • 112. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 113. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 114. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 115. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 116. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 117. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 118. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 119. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: we relax this Consider the same you relax the i-th edge in the shortest path from s to t. . . at some point shortest path from s to t
  • 120. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: we relax this Consider the same you relax the i-th edge in the shortest path from s to t. . . at some point Don’t worry about what ? was before. RELAX picks the smaller of ? and 0 + (−1) so. . . shortest path from s to t
  • 121. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: we relax this -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . at some point Don’t worry about what ? was before. RELAX picks the smaller of ? and 0 + (−1) so. . . shortest path from s to t
  • 122. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 123. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 124. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 125. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 126. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 127. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 128. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 129. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 130. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 131. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 132. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 133. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 134. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 135. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 136. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 137. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 138. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t Iteration 1: -1 Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 139. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 140. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 141. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 142. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 143. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 144. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 145. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: relax this Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t
  • 146. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: relax this Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 147. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 148. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 149. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 150. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 151. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 152. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 153. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 154. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 155. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 156. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 157. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 158. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 159. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 160. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 161. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 162. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 163. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 164. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 165. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 166. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 2: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 167. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 168. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 169. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 170. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 171. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 172. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 173. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 relax this Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3
  • 174. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 relax this Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 175. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 176. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 177. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 178. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 179. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 180. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 181. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 182. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 183. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 3: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 184. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 185. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 186. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 187. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 188. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 189. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 190. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 191. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 192. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 193. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 relax this Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2
  • 194. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 relax this Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 195. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 196. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 197. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 198. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 199. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 200. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 201. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 4: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 202. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 203. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 204. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 205. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 206. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 207. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 208. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 209. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 210. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 211. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 212. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 213. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 214. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 215. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 216. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 relax this Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1
  • 217. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 relax this Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 218. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 219. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 220. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 221. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 222. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 223. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 5: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 224. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 225. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 226. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 227. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 228. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 229. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 230. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 231. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 232. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0
  • 233. The proof idea Now consider the MOSTOFBELLMAN-FORD algorithm where in each iteration. . . s 0 ? ? ? ? ? ? ? ? ? ? ? 3 1 1 1 4 -2 2 2 -2 -1 1 1 -1 1 3 -1 -1 2 1 -2 1 you relax every edge (rather than one edge) At some point in iteration i t -1 Iteration 6: Consider the same you relax the i-th edge in the shortest path from s to t. . . shortest path from s to t -3 -2 -1 0