SlideShare a Scribd company logo
1 of 45
Algorithms L18.1
LECTURE 18
Shortest Paths II
• Bellman-Ford algorithm
• Linear programming and
difference constraints
• VLSI layout compaction
Algorithms
Algorithms L18.2
Negative-weight cycles
Recall: If a graph G = (V, E) contains a negative-
weight cycle, then some shortest paths may not
exist.Example:
uu vv
…
< 0
Algorithms L18.3
Negative-weight cycles
Recall: If a graph G = (V, E) contains a negative-
weight cycle, then some shortest paths may not
exist.Example:
uu vv
…
< 0
Bellman-Ford algorithm: Finds all shortest-path
lengths from a source s ∈ V to all v ∈ V or
determines that a negative-weight cycle exists.
Algorithms L18.4
Bellman-Ford algorithm
d[s] ← 0
for each v ∈ V – {s}
do d[v] ← ∞
for i ← 1 to |V| – 1
do for each edge (u, v) ∈ E
do if d[v] > d[u] + w(u, v)
then d[v] ← d[u] + w(u, v)
for each edge (u, v) ∈ E
do if d[v] > d[u] + w(u, v)
then report that a negative-weight cycle exists
initialization
At the end, d[v] = δ(s, v), if no negative-weight cycles.
Time = O(VE).
relaxation
step
Algorithms L18.5
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
Algorithms L18.6
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
∞
0 ∞
∞ ∞
Initialization.
Algorithms L18.7
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
∞
0 ∞
∞ ∞
1
2
3
4
5
7
8
Order of edge relaxation.
6
Algorithms L18.8
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
∞
0 ∞
∞ ∞
1
2
3
4
5
7
8
6
Algorithms L18.9
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
∞
0 ∞
∞ ∞
1
2
3
4
5
7
8
6
Algorithms L18.10
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
∞
0 ∞
∞ ∞
1
2
3
4
5
7
8
6
Algorithms L18.11
∞−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0 ∞
∞ ∞
1
2
3
4
5
7
8
6
Algorithms L18.12
∞4
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0 ∞
∞
1
2
3
4
5
7
8
6
Algorithms L18.13
4
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0 ∞
∞
1
2
3
4
5
7
8
6
Algorithms L18.14
42
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0 ∞
∞
1
2
3
4
5
7
8
6
Algorithms L18.15
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0 ∞
∞
1
2
3
4
5
7
8
6
Algorithms L18.16
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0 ∞
∞
1
2
3
4
5
7
8
End of pass 1.
6
Algorithms L18.17
∞1
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0
∞
1
2
3
4
5
7
8
6
Algorithms L18.18
1
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0
∞
1
2
3
4
5
7
8
6
Algorithms L18.19
∞1
1
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0
1
2
3
4
5
7
8
6
Algorithms L18.20
1
1
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0
1
2
3
4
5
7
8
6
Algorithms L18.21
1
1
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0
1
2
3
4
5
7
8
6
Algorithms L18.22
1
1
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0
1
2
3
4
5
7
8
6
Algorithms L18.23
1
1
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0
1
2
3
4
5
7
8
6
Algorithms L18.24
1−2
1
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0
1
2
3
4
5
7
8
6
Algorithms L18.25
−2
1
2
−1
Example of Bellman-Ford
AA
BB
EE
CC DD
–1
4
1
2
–3
2
5
3
0
1
2
3
4
5
7
8
6
End of pass 2 (and 3 and 4).
Algorithms L18.26
Correctness
Theorem. If G = (V, E) contains no negative-
weight cycles, then after the Bellman-Ford
algorithm executes, d[v] = δ(s, v) for all v ∈ V.
Algorithms L18.27
Correctness
Theorem. If G = (V, E) contains no negative-
weight cycles, then after the Bellman-Ford
algorithm executes, d[v] = δ(s, v) for all v ∈ V.
Proof. Let v ∈ V be any vertex, and consider a shortest
path p from s to v with the minimum number of edges.
v1
v1
v2
v2
v3
v3 vk
vk
v0
v0
…
s
v
p:
Since p is a shortest path, we have
δ(s, vi) = δ(s, vi–1) + w(vi–1, vi) .
Algorithms L18.28
Correctness (continued)
v1
v1
v2
v2
v3
v3 vk
vk
v0
v0
…
s
v
p:
Initially, d[v0] = 0 = δ(s, v0), and d[v0] is unchanged by
subsequent relaxations (because of the lemma from
Lecture 14 that d[v] ≥ δ(s, v)).
• After 1 pass through E, we have d[v1] = δ(s, v1).
• After 2 passes through E, we have d[v2] = δ(s, v2).

• After k passes through E, we have d[vk] = δ(s, vk).
Since G contains no negative-weight cycles, p is simple.
Longest simple path has ≤ |V| – 1 edges.
Algorithms L18.29
Detection of negative-weight
cycles
Corollary. If a value d[v] fails to converge after
|V| – 1 passes, there exists a negative-weight
cycle in G reachable from s.
Algorithms L18.30
Linear programming
Let A be an m×n matrix, b be an m-vector, and c
be an n-vector. Find an n-vector x that maximizes
cT
x subject to Ax ≤ b, or determine that no such
solution exists.
. ≤ .maximizingm
n
A x ≤ b cT
x
Algorithms L18.31
Linear-programming
algorithms
Algorithms for the general problem
• Simplex methods — practical, but worst-case
exponential time.
• Interior-point methods — polynomial time and
competes with simplex.
Algorithms L18.32
Linear-programming
algorithms
Algorithms for the general problem
• Simplex methods — practical, but worst-case
exponential time.
• Interior-point methods — polynomial time and
competes with simplex.
Feasibility problem: No optimization criterion.
Just find x such that Ax ≤ b.
• In general, just as hard as ordinary LP.
Algorithms L18.33
Solving a system of difference
constraints
Linear programming where each row of A contains
exactly one 1, one –1, and the rest 0’s.
Example:
x1 – x2 ≤ 3
x2 – x3 ≤ –2
x1 – x3 ≤ 2
xj – xi ≤ wij
Algorithms L18.34
Solving a system of difference
constraints
Linear programming where each row of A contains
exactly one 1, one –1, and the rest 0’s.
Example:
x1 – x2 ≤ 3
x2 – x3 ≤ –2
x1 – x3 ≤ 2
xj – xi ≤ wij
Solution:
x1 = 3
x2 = 0
x3 = 2
Algorithms L18.35
Solving a system of difference
constraints
Linear programming where each row of A contains
exactly one 1, one –1, and the rest 0’s.
Example:
x1 – x2 ≤ 3
x2 – x3 ≤ –2
x1 – x3 ≤ 2
xj – xi ≤ wij
Solution:
x1 = 3
x2 = 0
x3 = 2
Constraint graph:
vj
vjvi
vixj – xi ≤ wij
wij
(The “A”
matrix has
dimensions
|E| × |V|.)
Algorithms L18.36
Unsatisfiable constraints
Theorem. If the constraint graph contains
a negative-weight cycle, then the system of
differences is unsatisfiable.
Algorithms L18.37
Unsatisfiable constraints
Theorem. If the constraint graph contains
a negative-weight cycle, then the system of
differences is unsatisfiable.
Proof. Suppose that the negative-weight cycle is
v1 → v2 →  → vk → v1. Then, we have
x2 – x1 ≤ w12
x3 – x2 ≤ w23

xk – xk–1 ≤ wk–1, k
x1 – xk ≤ wk1
Algorithms L18.38
Unsatisfiable constraints
Theorem. If the constraint graph contains
a negative-weight cycle, then the system of
differences is unsatisfiable.
Proof. Suppose that the negative-weight cycle is
v1 → v2 →  → vk → v1. Then, we have
x2 – x1 ≤ w12
x3 – x2 ≤ w23

xk – xk–1 ≤ wk–1, k
x1 – xk ≤ wk1
Therefore, no
values for the xi
can satisfy the
constraints.
0 ≤ weight of cycle
< 0
Algorithms L18.39
Satisfying the constraints
Theorem. Suppose no negative-weight cycle
exists in the constraint graph. Then, the
constraints are satisfiable.
Algorithms L18.40
Satisfying the constraints
Theorem. Suppose no negative-weight cycle
exists in the constraint graph. Then, the
constraints are satisfiable.
Proof. Add a new vertex s to V with a 0-weight edge
to each vertex vi ∈ V.
v1
v1
v4
v4
v7
v7
v9
v9
v3
v3
Algorithms L18.41
Satisfying the constraints
Theorem. Suppose no negative-weight cycle
exists in the constraint graph. Then, the
constraints are satisfiable.
Proof. Add a new vertex s to V with a 0-weight edge
to each vertex vi ∈ V.
v1
v1
v4
v4
v7
v7
v9
v9
v3
v3
s
0 Note:
No negative-weight
cycles introduced ⇒
shortest paths exist.
Algorithms L18.42
The triangle inequality gives us δ(s,vj) ≤ δ(s, vi) + wij.
Since xi = δ(s, vi) and xj = δ(s, vj), the constraint xj – xi
≤ wij is satisfied.
Proof (continued)
Claim: The assignment xi = δ(s, vi) solves the constraints.
ss
vj
vj
vi
vi
δ(s, vi)
δ(s, vj) wij
Consider any constraint xj – xi ≤ wij, and consider the
shortest paths from s to vj and vi:
Algorithms L18.43
Bellman-Ford and linear
programming
Corollary. The Bellman-Ford algorithm can
solve a system of m difference constraints on n
variables in O(mn) time.
Single-source shortest paths is a simple LP
problem.
In fact, Bellman-Ford maximizes x1 + x2 +  + xn
subject to the constraints xj – xi ≤ wij and xi ≤ 0
(exercise).
Bellman-Ford also minimizes maxi{xi} – mini{xi}
(exercise).
Algorithms L18.44
Application to VLSI layout
compaction
Integrated
-circuit
features:
Problem: Compact (in one dimension) the
space between the features of a VLSI layout
without bringing any features too close together.
minimum separation λ
Algorithms L18.45
VLSI layout compaction
11
x1 x2
2
d1
Constraint: x2 – x1 ≥ d1 + λ
Bellman-Ford minimizes maxi{xi} – mini{xi},
which compacts the layout in the x-dimension.

More Related Content

What's hot

Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithmmansab MIRZA
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problemJayesh Chauhan
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplicationKiran K
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentationSubid Biswas
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesFahim Ferdous
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree methodRajendran
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithmsSaga Valsalan
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 
DAA-Floyd Warshall Algorithm.pptx
DAA-Floyd Warshall Algorithm.pptxDAA-Floyd Warshall Algorithm.pptx
DAA-Floyd Warshall Algorithm.pptxArbabMaalik
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithmRuchika Sinha
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplicationRespa Peter
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approachpadmeshagrekar
 

What's hot (20)

Dijkstra s algorithm
Dijkstra s algorithmDijkstra s algorithm
Dijkstra s algorithm
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problem
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
NP completeness
NP completenessNP completeness
NP completeness
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
DAA-Floyd Warshall Algorithm.pptx
DAA-Floyd Warshall Algorithm.pptxDAA-Floyd Warshall Algorithm.pptx
DAA-Floyd Warshall Algorithm.pptx
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 

Similar to Bellman Ford's Algorithm

Improving EV Lateral Dynamics Control Using Infinity Norm Approach with Close...
Improving EV Lateral Dynamics Control Using Infinity Norm Approach with Close...Improving EV Lateral Dynamics Control Using Infinity Norm Approach with Close...
Improving EV Lateral Dynamics Control Using Infinity Norm Approach with Close...Valerio Salvucci
 
bellman-ford Theorem.ppt
bellman-ford Theorem.pptbellman-ford Theorem.ppt
bellman-ford Theorem.pptSaimaShaheen14
 
Single sourceshortestpath by emad
Single sourceshortestpath by emadSingle sourceshortestpath by emad
Single sourceshortestpath by emadKazi Emad
 
about power system operation and control13197214.ppt
about power system operation and control13197214.pptabout power system operation and control13197214.ppt
about power system operation and control13197214.pptMohammedAhmed66819
 
ECE476_2016_Lect 12.pptx
ECE476_2016_Lect 12.pptxECE476_2016_Lect 12.pptx
ECE476_2016_Lect 12.pptxAhmed359095
 
Cooperative Collision Avoidance via Proximal Message Passing
Cooperative Collision Avoidance via Proximal Message PassingCooperative Collision Avoidance via Proximal Message Passing
Cooperative Collision Avoidance via Proximal Message PassingLyft
 
Random Matrix Theory and Machine Learning - Part 3
Random Matrix Theory and Machine Learning - Part 3Random Matrix Theory and Machine Learning - Part 3
Random Matrix Theory and Machine Learning - Part 3Fabian Pedregosa
 
Newton Raphson method for load flow analysis
Newton Raphson method for load flow analysisNewton Raphson method for load flow analysis
Newton Raphson method for load flow analysisdivyanshuprakashrock
 
lec-10-perceptron-upload.pdf
lec-10-perceptron-upload.pdflec-10-perceptron-upload.pdf
lec-10-perceptron-upload.pdfAntonio Espinosa
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sJay Patel
 
Lecture_10_Parallel_Algorithms_Part_II.ppt
Lecture_10_Parallel_Algorithms_Part_II.pptLecture_10_Parallel_Algorithms_Part_II.ppt
Lecture_10_Parallel_Algorithms_Part_II.pptWahyuAde4
 
Node Unique Label Cover
Node Unique Label CoverNode Unique Label Cover
Node Unique Label Covermsramanujan
 
test pre
test pretest pre
test prefarazch
 

Similar to Bellman Ford's Algorithm (20)

Improving EV Lateral Dynamics Control Using Infinity Norm Approach with Close...
Improving EV Lateral Dynamics Control Using Infinity Norm Approach with Close...Improving EV Lateral Dynamics Control Using Infinity Norm Approach with Close...
Improving EV Lateral Dynamics Control Using Infinity Norm Approach with Close...
 
bellman-ford Theorem.ppt
bellman-ford Theorem.pptbellman-ford Theorem.ppt
bellman-ford Theorem.ppt
 
Single sourceshortestpath by emad
Single sourceshortestpath by emadSingle sourceshortestpath by emad
Single sourceshortestpath by emad
 
about power system operation and control13197214.ppt
about power system operation and control13197214.pptabout power system operation and control13197214.ppt
about power system operation and control13197214.ppt
 
ECE476_2016_Lect 12.pptx
ECE476_2016_Lect 12.pptxECE476_2016_Lect 12.pptx
ECE476_2016_Lect 12.pptx
 
Cooperative Collision Avoidance via Proximal Message Passing
Cooperative Collision Avoidance via Proximal Message PassingCooperative Collision Avoidance via Proximal Message Passing
Cooperative Collision Avoidance via Proximal Message Passing
 
Random Matrix Theory and Machine Learning - Part 3
Random Matrix Theory and Machine Learning - Part 3Random Matrix Theory and Machine Learning - Part 3
Random Matrix Theory and Machine Learning - Part 3
 
Regression.pptx
Regression.pptxRegression.pptx
Regression.pptx
 
Regression.pptx
Regression.pptxRegression.pptx
Regression.pptx
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Newton Raphson method for load flow analysis
Newton Raphson method for load flow analysisNewton Raphson method for load flow analysis
Newton Raphson method for load flow analysis
 
lec-10-perceptron-upload.pdf
lec-10-perceptron-upload.pdflec-10-perceptron-upload.pdf
lec-10-perceptron-upload.pdf
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
 
smtlecture.6
smtlecture.6smtlecture.6
smtlecture.6
 
Lecture_10_Parallel_Algorithms_Part_II.ppt
Lecture_10_Parallel_Algorithms_Part_II.pptLecture_10_Parallel_Algorithms_Part_II.ppt
Lecture_10_Parallel_Algorithms_Part_II.ppt
 
QMC: Transition Workshop - Applying Quasi-Monte Carlo Methods to a Stochastic...
QMC: Transition Workshop - Applying Quasi-Monte Carlo Methods to a Stochastic...QMC: Transition Workshop - Applying Quasi-Monte Carlo Methods to a Stochastic...
QMC: Transition Workshop - Applying Quasi-Monte Carlo Methods to a Stochastic...
 
Node Unique Label Cover
Node Unique Label CoverNode Unique Label Cover
Node Unique Label Cover
 
Load_Flow.pptx
Load_Flow.pptxLoad_Flow.pptx
Load_Flow.pptx
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
test pre
test pretest pre
test pre
 

Recently uploaded

Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 

Recently uploaded (20)

Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 

Bellman Ford's Algorithm

  • 1. Algorithms L18.1 LECTURE 18 Shortest Paths II • Bellman-Ford algorithm • Linear programming and difference constraints • VLSI layout compaction Algorithms
  • 2. Algorithms L18.2 Negative-weight cycles Recall: If a graph G = (V, E) contains a negative- weight cycle, then some shortest paths may not exist.Example: uu vv … < 0
  • 3. Algorithms L18.3 Negative-weight cycles Recall: If a graph G = (V, E) contains a negative- weight cycle, then some shortest paths may not exist.Example: uu vv … < 0 Bellman-Ford algorithm: Finds all shortest-path lengths from a source s ∈ V to all v ∈ V or determines that a negative-weight cycle exists.
  • 4. Algorithms L18.4 Bellman-Ford algorithm d[s] ← 0 for each v ∈ V – {s} do d[v] ← ∞ for i ← 1 to |V| – 1 do for each edge (u, v) ∈ E do if d[v] > d[u] + w(u, v) then d[v] ← d[u] + w(u, v) for each edge (u, v) ∈ E do if d[v] > d[u] + w(u, v) then report that a negative-weight cycle exists initialization At the end, d[v] = δ(s, v), if no negative-weight cycles. Time = O(VE). relaxation step
  • 5. Algorithms L18.5 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3
  • 6. Algorithms L18.6 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 ∞ 0 ∞ ∞ ∞ Initialization.
  • 7. Algorithms L18.7 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 ∞ 0 ∞ ∞ ∞ 1 2 3 4 5 7 8 Order of edge relaxation. 6
  • 8. Algorithms L18.8 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 ∞ 0 ∞ ∞ ∞ 1 2 3 4 5 7 8 6
  • 9. Algorithms L18.9 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 ∞ 0 ∞ ∞ ∞ 1 2 3 4 5 7 8 6
  • 10. Algorithms L18.10 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 ∞ 0 ∞ ∞ ∞ 1 2 3 4 5 7 8 6
  • 11. Algorithms L18.11 ∞−1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 ∞ ∞ ∞ 1 2 3 4 5 7 8 6
  • 12. Algorithms L18.12 ∞4 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 ∞ ∞ 1 2 3 4 5 7 8 6
  • 13. Algorithms L18.13 4 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 ∞ ∞ 1 2 3 4 5 7 8 6
  • 14. Algorithms L18.14 42 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 ∞ ∞ 1 2 3 4 5 7 8 6
  • 15. Algorithms L18.15 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 ∞ ∞ 1 2 3 4 5 7 8 6
  • 16. Algorithms L18.16 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 ∞ ∞ 1 2 3 4 5 7 8 End of pass 1. 6
  • 17. Algorithms L18.17 ∞1 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 ∞ 1 2 3 4 5 7 8 6
  • 18. Algorithms L18.18 1 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 ∞ 1 2 3 4 5 7 8 6
  • 19. Algorithms L18.19 ∞1 1 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6
  • 20. Algorithms L18.20 1 1 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6
  • 21. Algorithms L18.21 1 1 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6
  • 22. Algorithms L18.22 1 1 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6
  • 23. Algorithms L18.23 1 1 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6
  • 24. Algorithms L18.24 1−2 1 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6
  • 25. Algorithms L18.25 −2 1 2 −1 Example of Bellman-Ford AA BB EE CC DD –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6 End of pass 2 (and 3 and 4).
  • 26. Algorithms L18.26 Correctness Theorem. If G = (V, E) contains no negative- weight cycles, then after the Bellman-Ford algorithm executes, d[v] = δ(s, v) for all v ∈ V.
  • 27. Algorithms L18.27 Correctness Theorem. If G = (V, E) contains no negative- weight cycles, then after the Bellman-Ford algorithm executes, d[v] = δ(s, v) for all v ∈ V. Proof. Let v ∈ V be any vertex, and consider a shortest path p from s to v with the minimum number of edges. v1 v1 v2 v2 v3 v3 vk vk v0 v0 … s v p: Since p is a shortest path, we have δ(s, vi) = δ(s, vi–1) + w(vi–1, vi) .
  • 28. Algorithms L18.28 Correctness (continued) v1 v1 v2 v2 v3 v3 vk vk v0 v0 … s v p: Initially, d[v0] = 0 = δ(s, v0), and d[v0] is unchanged by subsequent relaxations (because of the lemma from Lecture 14 that d[v] ≥ δ(s, v)). • After 1 pass through E, we have d[v1] = δ(s, v1). • After 2 passes through E, we have d[v2] = δ(s, v2).  • After k passes through E, we have d[vk] = δ(s, vk). Since G contains no negative-weight cycles, p is simple. Longest simple path has ≤ |V| – 1 edges.
  • 29. Algorithms L18.29 Detection of negative-weight cycles Corollary. If a value d[v] fails to converge after |V| – 1 passes, there exists a negative-weight cycle in G reachable from s.
  • 30. Algorithms L18.30 Linear programming Let A be an m×n matrix, b be an m-vector, and c be an n-vector. Find an n-vector x that maximizes cT x subject to Ax ≤ b, or determine that no such solution exists. . ≤ .maximizingm n A x ≤ b cT x
  • 31. Algorithms L18.31 Linear-programming algorithms Algorithms for the general problem • Simplex methods — practical, but worst-case exponential time. • Interior-point methods — polynomial time and competes with simplex.
  • 32. Algorithms L18.32 Linear-programming algorithms Algorithms for the general problem • Simplex methods — practical, but worst-case exponential time. • Interior-point methods — polynomial time and competes with simplex. Feasibility problem: No optimization criterion. Just find x such that Ax ≤ b. • In general, just as hard as ordinary LP.
  • 33. Algorithms L18.33 Solving a system of difference constraints Linear programming where each row of A contains exactly one 1, one –1, and the rest 0’s. Example: x1 – x2 ≤ 3 x2 – x3 ≤ –2 x1 – x3 ≤ 2 xj – xi ≤ wij
  • 34. Algorithms L18.34 Solving a system of difference constraints Linear programming where each row of A contains exactly one 1, one –1, and the rest 0’s. Example: x1 – x2 ≤ 3 x2 – x3 ≤ –2 x1 – x3 ≤ 2 xj – xi ≤ wij Solution: x1 = 3 x2 = 0 x3 = 2
  • 35. Algorithms L18.35 Solving a system of difference constraints Linear programming where each row of A contains exactly one 1, one –1, and the rest 0’s. Example: x1 – x2 ≤ 3 x2 – x3 ≤ –2 x1 – x3 ≤ 2 xj – xi ≤ wij Solution: x1 = 3 x2 = 0 x3 = 2 Constraint graph: vj vjvi vixj – xi ≤ wij wij (The “A” matrix has dimensions |E| × |V|.)
  • 36. Algorithms L18.36 Unsatisfiable constraints Theorem. If the constraint graph contains a negative-weight cycle, then the system of differences is unsatisfiable.
  • 37. Algorithms L18.37 Unsatisfiable constraints Theorem. If the constraint graph contains a negative-weight cycle, then the system of differences is unsatisfiable. Proof. Suppose that the negative-weight cycle is v1 → v2 →  → vk → v1. Then, we have x2 – x1 ≤ w12 x3 – x2 ≤ w23  xk – xk–1 ≤ wk–1, k x1 – xk ≤ wk1
  • 38. Algorithms L18.38 Unsatisfiable constraints Theorem. If the constraint graph contains a negative-weight cycle, then the system of differences is unsatisfiable. Proof. Suppose that the negative-weight cycle is v1 → v2 →  → vk → v1. Then, we have x2 – x1 ≤ w12 x3 – x2 ≤ w23  xk – xk–1 ≤ wk–1, k x1 – xk ≤ wk1 Therefore, no values for the xi can satisfy the constraints. 0 ≤ weight of cycle < 0
  • 39. Algorithms L18.39 Satisfying the constraints Theorem. Suppose no negative-weight cycle exists in the constraint graph. Then, the constraints are satisfiable.
  • 40. Algorithms L18.40 Satisfying the constraints Theorem. Suppose no negative-weight cycle exists in the constraint graph. Then, the constraints are satisfiable. Proof. Add a new vertex s to V with a 0-weight edge to each vertex vi ∈ V. v1 v1 v4 v4 v7 v7 v9 v9 v3 v3
  • 41. Algorithms L18.41 Satisfying the constraints Theorem. Suppose no negative-weight cycle exists in the constraint graph. Then, the constraints are satisfiable. Proof. Add a new vertex s to V with a 0-weight edge to each vertex vi ∈ V. v1 v1 v4 v4 v7 v7 v9 v9 v3 v3 s 0 Note: No negative-weight cycles introduced ⇒ shortest paths exist.
  • 42. Algorithms L18.42 The triangle inequality gives us δ(s,vj) ≤ δ(s, vi) + wij. Since xi = δ(s, vi) and xj = δ(s, vj), the constraint xj – xi ≤ wij is satisfied. Proof (continued) Claim: The assignment xi = δ(s, vi) solves the constraints. ss vj vj vi vi δ(s, vi) δ(s, vj) wij Consider any constraint xj – xi ≤ wij, and consider the shortest paths from s to vj and vi:
  • 43. Algorithms L18.43 Bellman-Ford and linear programming Corollary. The Bellman-Ford algorithm can solve a system of m difference constraints on n variables in O(mn) time. Single-source shortest paths is a simple LP problem. In fact, Bellman-Ford maximizes x1 + x2 +  + xn subject to the constraints xj – xi ≤ wij and xi ≤ 0 (exercise). Bellman-Ford also minimizes maxi{xi} – mini{xi} (exercise).
  • 44. Algorithms L18.44 Application to VLSI layout compaction Integrated -circuit features: Problem: Compact (in one dimension) the space between the features of a VLSI layout without bringing any features too close together. minimum separation λ
  • 45. Algorithms L18.45 VLSI layout compaction 11 x1 x2 2 d1 Constraint: x2 – x1 ≥ d1 + λ Bellman-Ford minimizes maxi{xi} – mini{xi}, which compacts the layout in the x-dimension.