SlideShare a Scribd company logo
1 of 43
SINGLE-SOURCE SHORTEST PATHS
Shortest Path Problems
• Directed weighted graph.
• Path length is sum of weights of edges on path.
• The vertex at which the path begins is the source vertex.
• The vertex at which the path ends is the destination vertex.
0
3 9
5 11
3
6
5
7
6
s
t x
y z
2
2 1
4
3
Example
1
2
3
4
5
6
7
2
6
16
7
8
10
3
14
4
4
5 3
1
1
7
• Consider Source node 1 and destination node 7
• A direct path between Nodes 1 and 7 will cost 14
Example
1
2
3
4
5
6
7
2
6
16
7
8
10
3
14
4
4
5 3
1
• A shorter path will cost only 11
Shortest-Path Variants
• Single-source single-destination (1-1): Find the shortest
path from source s to destination v.
• Single-source all-destination(1-Many): Find the shortest
path from s to each vertex v.
• Single-destination shortest-paths (Many-1): Find a shortest
path to a given destination vertex t from each vertex v.
• All-pairs shortest-paths problem (Many-Many): Find a
shortest path from u to v for every pair of vertices u and v.
We talk about directed, weighted graphs
Shortest-Path Variants (Cont’d)
• For un-weighted graphs, the shortest path problem is mapped to BFS
– Since all weights are the same, we search for the smallest number of edges
s
2
5
4
7
8
3 6 9
0
1
1
1
2
2
3
3
3
BFS creates a tree called BFS-Tree
Shortest-Path Variants
• Single-source single-destination (1-1): Find the shortest
path from source s to destination v.
• Single-source all-destination(1-Many): Find the shortest
path from s to each vertex v.
• Single-destination shortest-paths (Many-1): Find a shortest
path to a given destination vertex t from each vertex v.
• All-pairs shortest-paths problem (Many-Many): Find a
shortest path from u to v for every pair of vertices u and v.
No need to consider different solution or algorithm for each variant
(we reduce it into two types)
Shortest-Path Variants
Single-Source Single-Destination (1-1)
- No good solution that beats 1-M variant
- Thus, this problem is mapped to the 1-M
variant
Single-Source All-Destination (1-M)
- Need to be solved (several algorithms)
- We will study this one
All-Sources Single-Destination (M-1)
- Reverse all edges in the graph
- Thus, it is mapped to the (1-M) variant
All-Sources All-Destinations (M-M)
- Need to be solved (several algorithms)
- We will study it (if time permits)
Shortest-Path Variants
Single-Source Single-Destination (1-1)
- No good solution that beats 1-M variant
- Thus, this problem is mapped to the 1-M
variant
Single-Source All-Destination (1-M)
- Need to be solved (several algorithms)
- We will study this one
All-Sources Single-Destination (M-1)
- Reverse all edges in the graph
- Thus, it is mapped to the (1-M) variant
All-Sources All-Destinations (M-M)
- Need to be solved (several algorithms)
- We will study it (if time permits)
Introduction
Generalization of BFS to handle weighted graphs
• Direct Graph G = ( V, E ), edge weight fn ; w : E → R
• In BFS w(e)=1 for all e  E
Weight of path p = v1  v2  …  vk is
1
1
1
( ) ( , )
k
i i
i
w p w v v



 
Shortest Path
Shortest Path = Path of minimum weight
δ(u,v)= min{ω(p) : u v}; if there is a path from u to v,
 otherwise.
p
Several Properties
1- Optimal Substructure Property
Theorem: Subpaths of shortest paths are also shortest paths
• Let δ(1,k) = <v1, ..i, .. j.., .. ,vk > be a shortest path from v1 to vk
• Let δ(i,j) = <vi, ... ,vj > be subpath of δ(1,k) from vi to vj
for any i, j
• Then δ(I,j) is a shortest path from vi to vj
Proof: By cut and paste
• If some subpath were not a shortest path
• We could substitute a shorter subpath to create a shorter
total path
• Hence, the original path would not be shortest path
v2
v3 v4
v5 v6 v7
1- Optimal Substructure Property
v1
v0
Definition:
• δ(u,v) = weight of the shortest path(s) from u to v
• Negative-weight cycle: The problem is undefined
– can always get a shorter path by going around the cycle again
• Positive-weight cycle : can be taken out and reduces the cost
s v
cycle
< 0
2- No Cycles in Shortest Path
3- Negative-weight edges
• No problem, as long as no negative-weight cycles are
reachable from the source (allowed)
4- Triangle Inequality
Lemma 1: for a given vertex s in V and for every edge (u,v) in E,
• δ(s,v) ≤ δ(s,u) + w(u,v)
Proof: shortest path s v is no longer than any other path.
• in particular the path that takes the shortest path s v and
then takes cycle (u,v)
s
u v
Algorithms to Cover
• Dijkstra’s Algorithm
• Shortest Path is DAGs
Initialization
• Maintain d[v] for each v in V
• d[v] is called shortest-path weight estimate
and it is upper bound on δ(s,v)
INIT(G, s)
for each v  V do
d[v] ← ∞
π[v] ← NIL
d[s] ← 0
Parent node
Upper bound
Relaxation
RELAX(u, v)
if d[v] > d[u]+w(u,v) then
d[v] ← d[u]+w(u,v)
π[v] ← u
5
u v
v
u
2
2
9
5 7
Change d[v]
5
u v
v
u
2
2
6
5 6
When you find an edge (u,v) then
check this condition and relax d[v] if
possible
No chnage
Algorithms to Cover
• Dijkstra’s Algorithm
• Shortest Path is DAGs
• Non-negative edge weight
• Like BFS: If all edge weights are equal, then use BFS,
otherwise use this algorithm
• Use Q = min-priority queue keyed on d[v] values
Dijkstra’s Algorithm For Shortest Paths
DIJKSTRA(G, s)
INIT(G, s)
S←Ø > set of discovered nodes
Q←V[G]
while Q ≠Ø do
u←EXTRACT-MIN(Q)
S←S U {u}
for each v in Adj[u] do
RELAX(u, v) > May cause
> DECREASE-KEY(Q, v, d[v])
Dijkstra’s Algorithm For Shortest Paths
Example: Initialization Step
3
¥ ¥
¥ ¥
0
s
u v
y
x
10
5
1
2 9
4 6
7
2
DIJKSTRA(G, s)
INIT(G, s)
S←Ø > set of discovered nodes
Q←V[G]
while Q ≠Ø do
u←EXTRACT-MIN(Q)
S←S U {u}
for each v in Adj[u] do
RELAX(u, v) > May cause
> DECREASE-KEY(Q, v, d[v])
Example
3
 
 
0
s
u v
y
x
10
5
1
2 9
4 6
7
2
Example
2
10 
5 
0
s
u v
y
x
10
5
1
3
9
4 6
7
2
DIJKSTRA(G, s)
INIT(G, s)
S←Ø > set of discovered nodes
Q←V[G]
while Q ≠Ø do
u←EXTRACT-MIN(Q)
S←S U {u}
for each v in Adj[u] do
RELAX(u, v) > May cause
> DECREASE-KEY(Q, v, d[v])
Example
2
8 14
5 7
0
s
y
x
10
5
1
3 9
4 6
7
2
u v
DIJKSTRA(G, s)
INIT(G, s)
S←Ø > set of discovered nodes
Q←V[G]
while Q ≠Ø do
u←EXTRACT-MIN(Q)
S←S U {u}
for each v in Adj[u] do
RELAX(u, v) > May cause
> DECREASE-KEY(Q, v, d[v])
Example
10
8 13
5 7
0
s
u v
y
x
5
1
2 3 9
4 6
7
2
DIJKSTRA(G, s)
INIT(G, s)
S←Ø > set of discovered nodes
Q←V[G]
while Q ≠Ø do
u←EXTRACT-MIN(Q)
S←S U {u}
for each v in Adj[u] do
RELAX(u, v) > May cause
> DECREASE-KEY(Q, v, d[v])
Example
8
u v
9
5 7
0
y
x
10
5
1
2 3 9
4 6
7
2
s
DIJKSTRA(G, s)
INIT(G, s)
S←Ø > set of discovered nodes
Q←V[G]
while Q ≠Ø do
u←EXTRACT-MIN(Q)
S←S U {u}
for each v in Adj[u] do
RELAX(u, v) > May cause
> DECREASE-KEY(Q, v, d[v])
Example
u
5
8 9
5 7
0
v
y
x
10
1
2 3 9
4 6
7
2
s
Dijkstra’s Algorithm Analysis
DIJKSTRA(G, s)
INIT(G, s)
S←Ø > set of discovered nodes
Q←V[G]
while Q ≠Ø do
u←EXTRACT-MIN(Q)
S←S U {u}
for each v in Adj[u] do
RELAX(u, v) > May cause
> DECREASE-KEY(Q, v, d[v])
O(V)
O(V Log V)
Total in the loop: O(V Log V)
Total in the loop: O(E Log V)
Time Complexity: O (E Log V)
Algorithms to Cover
• Dijkstra’s Algorithm
• Shortest Path is DAGs
Key Property in DAGs
• If there are no cycles  it is called a DAG
• In DAGs, nodes can be sorted in a linear order such that all
edges are forward edges
– Topological sort
Single-Source Shortest Paths in DAGs
• Shortest paths are always well-defined in dags
 no cycles => no negative-weight cycles even if
there are negative-weight edges
• Idea: If we were lucky
 To process vertices on each shortest path from left
to right, we would be done in 1 pass
Single-Source Shortest Paths in DAGs
DAG-SHORTEST PATHS(G, s)
TOPOLOGICALLY-SORT the vertices of G
INIT(G, s)
for each vertex u taken in topologically sorted order do
for each v in Adj[u] do
RELAX(u, v)
Example
 0    
r s t u v w
5 2 7 –1 –2
6 1
3
2
4
Example
 0    
r s t u v w
5 2 7 –1 –2
6 1
3
2
4
Example
 0 2 6  
r s t u v w
5 2 7 –1 –2
6 1
3
2
4
Example
 0 2 6 6 4
r s t u v w
5 2 7 –1 –2
6 1
3
2
4
Example
 0 2 6 5 4
r s t u v w
5 2 7 –1 –2
6 1
3
2
4
Example
 0 2 6 5 3
r s t u v w
5 2 7 –1 –2
6 1
3
2
4
Example
 0 2 6 5 3
r s t u v w
5 2 7 –1 –2
6 1
3
2
4
Single-Source Shortest Paths in
DAGs: Analysis
DAG-SHORTEST PATHS(G, s)
TOPOLOGICALLY-SORT the vertices of G
INIT(G, s)
for each vertex u taken in topologically sorted order do
for each v in Adj[u] do
RELAX(u, v)
O(V+E)
O(V)
Total O(E)
Time Complexity: O (V + E)

More Related Content

What's hot (20)

Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Shortest path problem
Shortest path problemShortest path problem
Shortest path problem
 
The Floyd–Warshall algorithm
The Floyd–Warshall algorithmThe Floyd–Warshall algorithm
The Floyd–Warshall algorithm
 
Operator precedence
Operator precedenceOperator precedence
Operator precedence
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
 
N queen problem
N queen problemN queen problem
N queen problem
 
3.2 partitioning methods
3.2 partitioning methods3.2 partitioning methods
3.2 partitioning methods
 
K mean-clustering
K mean-clusteringK mean-clustering
K mean-clustering
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithm
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
 
Shortest path algorithm
Shortest  path algorithmShortest  path algorithm
Shortest path algorithm
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 

Similar to Shortest path

Inroduction_To_Algorithms_Lect14
Inroduction_To_Algorithms_Lect14Inroduction_To_Algorithms_Lect14
Inroduction_To_Algorithms_Lect14Naor Ami
 
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdfDKTaxation
 
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
 
lecture 21
lecture 21lecture 21
lecture 21sajinsc
 
Bellman Ford Algorithm
Bellman Ford AlgorithmBellman Ford Algorithm
Bellman Ford Algorithmiqra593488
 
Single source shortes path in dag
Single source shortes path in dagSingle source shortes path in dag
Single source shortes path in dagKiran K
 
Design and Analysis of Algorithm -Shortest paths problem
Design and Analysis of Algorithm -Shortest paths problemDesign and Analysis of Algorithm -Shortest paths problem
Design and Analysis of Algorithm -Shortest paths problempooja saini
 
Shortest Path Problem.docx
Shortest Path Problem.docxShortest Path Problem.docx
Shortest Path Problem.docxSeethaDinesh
 
04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2MuradAmn
 
Algorithm to count number of disjoint paths
Algorithm to count number of disjoint pathsAlgorithm to count number of disjoint paths
Algorithm to count number of disjoint pathsSujith Jay Nair
 
Lecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdfLecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdfiftakhar8
 

Similar to Shortest path (20)

Inroduction_To_Algorithms_Lect14
Inroduction_To_Algorithms_Lect14Inroduction_To_Algorithms_Lect14
Inroduction_To_Algorithms_Lect14
 
Graph 3
Graph 3Graph 3
Graph 3
 
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
 
Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Shortest path algorithms
Shortest path algorithmsShortest path algorithms
Shortest path algorithms
 
lecture 21
lecture 21lecture 21
lecture 21
 
Bellman Ford Algorithm
Bellman Ford AlgorithmBellman Ford Algorithm
Bellman Ford Algorithm
 
Single source shortes path in dag
Single source shortes path in dagSingle source shortes path in dag
Single source shortes path in dag
 
Design and Analysis of Algorithm -Shortest paths problem
Design and Analysis of Algorithm -Shortest paths problemDesign and Analysis of Algorithm -Shortest paths problem
Design and Analysis of Algorithm -Shortest paths problem
 
Shortest Path Problem.docx
Shortest Path Problem.docxShortest Path Problem.docx
Shortest Path Problem.docx
 
04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2
 
Algorithm to count number of disjoint paths
Algorithm to count number of disjoint pathsAlgorithm to count number of disjoint paths
Algorithm to count number of disjoint paths
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
8783733
87837338783733
8783733
 
dijkstraC.ppt
dijkstraC.pptdijkstraC.ppt
dijkstraC.ppt
 
Spsp fw
Spsp fwSpsp fw
Spsp fw
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
path
pathpath
path
 
Lecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdfLecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdf
 

More from Ruchika Sinha

Greedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.pptGreedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.pptRuchika Sinha
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptRuchika Sinha
 
Greedy Algorithms Huffman Coding.ppt
Greedy Algorithms  Huffman Coding.pptGreedy Algorithms  Huffman Coding.ppt
Greedy Algorithms Huffman Coding.pptRuchika Sinha
 
DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.pptRuchika Sinha
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptRuchika Sinha
 
Installation of motherboard
Installation of motherboardInstallation of motherboard
Installation of motherboardRuchika Sinha
 
Optimization problems
Optimization problemsOptimization problems
Optimization problemsRuchika Sinha
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithmRuchika Sinha
 
Software for encrypting and decrypting text file powerpointpresentation
Software for encrypting and decrypting text file powerpointpresentationSoftware for encrypting and decrypting text file powerpointpresentation
Software for encrypting and decrypting text file powerpointpresentationRuchika Sinha
 

More from Ruchika Sinha (20)

Greedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.pptGreedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.ppt
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
 
Greedy Algorithms Huffman Coding.ppt
Greedy Algorithms  Huffman Coding.pptGreedy Algorithms  Huffman Coding.ppt
Greedy Algorithms Huffman Coding.ppt
 
DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.ppt
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
 
Clipping
ClippingClipping
Clipping
 
Lec22 intel
Lec22 intelLec22 intel
Lec22 intel
 
Pc assembly
Pc assemblyPc assembly
Pc assembly
 
Casing
CasingCasing
Casing
 
Installation of motherboard
Installation of motherboardInstallation of motherboard
Installation of motherboard
 
Python material
Python materialPython material
Python material
 
Python3
Python3Python3
Python3
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
Regular Grammar
Regular GrammarRegular Grammar
Regular Grammar
 
Software Teting
Software TetingSoftware Teting
Software Teting
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
 
XML
XMLXML
XML
 
Software for encrypting and decrypting text file powerpointpresentation
Software for encrypting and decrypting text file powerpointpresentationSoftware for encrypting and decrypting text file powerpointpresentation
Software for encrypting and decrypting text file powerpointpresentation
 
Type casting
Type castingType casting
Type casting
 

Recently uploaded

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...Call girls in Ahmedabad High profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 

Recently uploaded (20)

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 

Shortest path

  • 2. Shortest Path Problems • Directed weighted graph. • Path length is sum of weights of edges on path. • The vertex at which the path begins is the source vertex. • The vertex at which the path ends is the destination vertex. 0 3 9 5 11 3 6 5 7 6 s t x y z 2 2 1 4 3
  • 3. Example 1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 1 7 • Consider Source node 1 and destination node 7 • A direct path between Nodes 1 and 7 will cost 14
  • 5. Shortest-Path Variants • Single-source single-destination (1-1): Find the shortest path from source s to destination v. • Single-source all-destination(1-Many): Find the shortest path from s to each vertex v. • Single-destination shortest-paths (Many-1): Find a shortest path to a given destination vertex t from each vertex v. • All-pairs shortest-paths problem (Many-Many): Find a shortest path from u to v for every pair of vertices u and v. We talk about directed, weighted graphs
  • 6. Shortest-Path Variants (Cont’d) • For un-weighted graphs, the shortest path problem is mapped to BFS – Since all weights are the same, we search for the smallest number of edges s 2 5 4 7 8 3 6 9 0 1 1 1 2 2 3 3 3 BFS creates a tree called BFS-Tree
  • 7. Shortest-Path Variants • Single-source single-destination (1-1): Find the shortest path from source s to destination v. • Single-source all-destination(1-Many): Find the shortest path from s to each vertex v. • Single-destination shortest-paths (Many-1): Find a shortest path to a given destination vertex t from each vertex v. • All-pairs shortest-paths problem (Many-Many): Find a shortest path from u to v for every pair of vertices u and v. No need to consider different solution or algorithm for each variant (we reduce it into two types)
  • 8. Shortest-Path Variants Single-Source Single-Destination (1-1) - No good solution that beats 1-M variant - Thus, this problem is mapped to the 1-M variant Single-Source All-Destination (1-M) - Need to be solved (several algorithms) - We will study this one All-Sources Single-Destination (M-1) - Reverse all edges in the graph - Thus, it is mapped to the (1-M) variant All-Sources All-Destinations (M-M) - Need to be solved (several algorithms) - We will study it (if time permits)
  • 9. Shortest-Path Variants Single-Source Single-Destination (1-1) - No good solution that beats 1-M variant - Thus, this problem is mapped to the 1-M variant Single-Source All-Destination (1-M) - Need to be solved (several algorithms) - We will study this one All-Sources Single-Destination (M-1) - Reverse all edges in the graph - Thus, it is mapped to the (1-M) variant All-Sources All-Destinations (M-M) - Need to be solved (several algorithms) - We will study it (if time permits)
  • 10. Introduction Generalization of BFS to handle weighted graphs • Direct Graph G = ( V, E ), edge weight fn ; w : E → R • In BFS w(e)=1 for all e  E Weight of path p = v1  v2  …  vk is 1 1 1 ( ) ( , ) k i i i w p w v v     
  • 11. Shortest Path Shortest Path = Path of minimum weight δ(u,v)= min{ω(p) : u v}; if there is a path from u to v,  otherwise. p
  • 13. 1- Optimal Substructure Property Theorem: Subpaths of shortest paths are also shortest paths • Let δ(1,k) = <v1, ..i, .. j.., .. ,vk > be a shortest path from v1 to vk • Let δ(i,j) = <vi, ... ,vj > be subpath of δ(1,k) from vi to vj for any i, j • Then δ(I,j) is a shortest path from vi to vj
  • 14. Proof: By cut and paste • If some subpath were not a shortest path • We could substitute a shorter subpath to create a shorter total path • Hence, the original path would not be shortest path v2 v3 v4 v5 v6 v7 1- Optimal Substructure Property v1 v0
  • 15. Definition: • δ(u,v) = weight of the shortest path(s) from u to v • Negative-weight cycle: The problem is undefined – can always get a shorter path by going around the cycle again • Positive-weight cycle : can be taken out and reduces the cost s v cycle < 0 2- No Cycles in Shortest Path
  • 16. 3- Negative-weight edges • No problem, as long as no negative-weight cycles are reachable from the source (allowed)
  • 17. 4- Triangle Inequality Lemma 1: for a given vertex s in V and for every edge (u,v) in E, • δ(s,v) ≤ δ(s,u) + w(u,v) Proof: shortest path s v is no longer than any other path. • in particular the path that takes the shortest path s v and then takes cycle (u,v) s u v
  • 18. Algorithms to Cover • Dijkstra’s Algorithm • Shortest Path is DAGs
  • 19. Initialization • Maintain d[v] for each v in V • d[v] is called shortest-path weight estimate and it is upper bound on δ(s,v) INIT(G, s) for each v  V do d[v] ← ∞ π[v] ← NIL d[s] ← 0 Parent node Upper bound
  • 20. Relaxation RELAX(u, v) if d[v] > d[u]+w(u,v) then d[v] ← d[u]+w(u,v) π[v] ← u 5 u v v u 2 2 9 5 7 Change d[v] 5 u v v u 2 2 6 5 6 When you find an edge (u,v) then check this condition and relax d[v] if possible No chnage
  • 21. Algorithms to Cover • Dijkstra’s Algorithm • Shortest Path is DAGs
  • 22. • Non-negative edge weight • Like BFS: If all edge weights are equal, then use BFS, otherwise use this algorithm • Use Q = min-priority queue keyed on d[v] values Dijkstra’s Algorithm For Shortest Paths
  • 23. DIJKSTRA(G, s) INIT(G, s) S←Ø > set of discovered nodes Q←V[G] while Q ≠Ø do u←EXTRACT-MIN(Q) S←S U {u} for each v in Adj[u] do RELAX(u, v) > May cause > DECREASE-KEY(Q, v, d[v]) Dijkstra’s Algorithm For Shortest Paths
  • 24. Example: Initialization Step 3 ¥ ¥ ¥ ¥ 0 s u v y x 10 5 1 2 9 4 6 7 2 DIJKSTRA(G, s) INIT(G, s) S←Ø > set of discovered nodes Q←V[G] while Q ≠Ø do u←EXTRACT-MIN(Q) S←S U {u} for each v in Adj[u] do RELAX(u, v) > May cause > DECREASE-KEY(Q, v, d[v])
  • 25. Example 3     0 s u v y x 10 5 1 2 9 4 6 7 2
  • 26. Example 2 10  5  0 s u v y x 10 5 1 3 9 4 6 7 2 DIJKSTRA(G, s) INIT(G, s) S←Ø > set of discovered nodes Q←V[G] while Q ≠Ø do u←EXTRACT-MIN(Q) S←S U {u} for each v in Adj[u] do RELAX(u, v) > May cause > DECREASE-KEY(Q, v, d[v])
  • 27. Example 2 8 14 5 7 0 s y x 10 5 1 3 9 4 6 7 2 u v DIJKSTRA(G, s) INIT(G, s) S←Ø > set of discovered nodes Q←V[G] while Q ≠Ø do u←EXTRACT-MIN(Q) S←S U {u} for each v in Adj[u] do RELAX(u, v) > May cause > DECREASE-KEY(Q, v, d[v])
  • 28. Example 10 8 13 5 7 0 s u v y x 5 1 2 3 9 4 6 7 2 DIJKSTRA(G, s) INIT(G, s) S←Ø > set of discovered nodes Q←V[G] while Q ≠Ø do u←EXTRACT-MIN(Q) S←S U {u} for each v in Adj[u] do RELAX(u, v) > May cause > DECREASE-KEY(Q, v, d[v])
  • 29. Example 8 u v 9 5 7 0 y x 10 5 1 2 3 9 4 6 7 2 s DIJKSTRA(G, s) INIT(G, s) S←Ø > set of discovered nodes Q←V[G] while Q ≠Ø do u←EXTRACT-MIN(Q) S←S U {u} for each v in Adj[u] do RELAX(u, v) > May cause > DECREASE-KEY(Q, v, d[v])
  • 31. Dijkstra’s Algorithm Analysis DIJKSTRA(G, s) INIT(G, s) S←Ø > set of discovered nodes Q←V[G] while Q ≠Ø do u←EXTRACT-MIN(Q) S←S U {u} for each v in Adj[u] do RELAX(u, v) > May cause > DECREASE-KEY(Q, v, d[v]) O(V) O(V Log V) Total in the loop: O(V Log V) Total in the loop: O(E Log V) Time Complexity: O (E Log V)
  • 32. Algorithms to Cover • Dijkstra’s Algorithm • Shortest Path is DAGs
  • 33. Key Property in DAGs • If there are no cycles  it is called a DAG • In DAGs, nodes can be sorted in a linear order such that all edges are forward edges – Topological sort
  • 34. Single-Source Shortest Paths in DAGs • Shortest paths are always well-defined in dags  no cycles => no negative-weight cycles even if there are negative-weight edges • Idea: If we were lucky  To process vertices on each shortest path from left to right, we would be done in 1 pass
  • 35. Single-Source Shortest Paths in DAGs DAG-SHORTEST PATHS(G, s) TOPOLOGICALLY-SORT the vertices of G INIT(G, s) for each vertex u taken in topologically sorted order do for each v in Adj[u] do RELAX(u, v)
  • 36. Example  0     r s t u v w 5 2 7 –1 –2 6 1 3 2 4
  • 37. Example  0     r s t u v w 5 2 7 –1 –2 6 1 3 2 4
  • 38. Example  0 2 6   r s t u v w 5 2 7 –1 –2 6 1 3 2 4
  • 39. Example  0 2 6 6 4 r s t u v w 5 2 7 –1 –2 6 1 3 2 4
  • 40. Example  0 2 6 5 4 r s t u v w 5 2 7 –1 –2 6 1 3 2 4
  • 41. Example  0 2 6 5 3 r s t u v w 5 2 7 –1 –2 6 1 3 2 4
  • 42. Example  0 2 6 5 3 r s t u v w 5 2 7 –1 –2 6 1 3 2 4
  • 43. Single-Source Shortest Paths in DAGs: Analysis DAG-SHORTEST PATHS(G, s) TOPOLOGICALLY-SORT the vertices of G INIT(G, s) for each vertex u taken in topologically sorted order do for each v in Adj[u] do RELAX(u, v) O(V+E) O(V) Total O(E) Time Complexity: O (V + E)