SlideShare a Scribd company logo
1 of 72
Download to read offline
Shortest Path, Bellman-Ford algorithm, Dijkstra’s algorithm,
and Applications
by
Dr.Animesh Chaturvedi
Assistant Professor: LNMIIT Jaipur
Post Doctorate: King’s College London &TheAlanTuring Institute
PhD: IIT Indore
Graph and Shortest Path
 Adjacency-list andAdjacency-matrix representation of undirected graph G with 5
vertices and 7 edges.
 Adjacency-list andAdjacency-matrix representations of a directed graph G with 6
vertices and 8 edges.
Graph representations
Shortest Path
 Given a road map of the India on which the distance between each pair of adjacent
intersections is marked between route from Delhi to Mumbai, how can you find
the shortest possible route?
 To examine an enormous number of possibilities, most of which are simply not
worth considering!
 Model the road map as a graph vertices represent intersections, edges represent
road segments between intersections, and edge weights represent road distances.
 For other examples weights can represent metrics other than distances, such as
time, cost, penalties, loss, or any other quantity that accumulates.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Shortest Path
 In a shortest-paths problem, given a weighted directed graph G = (V, E) with
edges mapped to real-valued weights.
 The weight w(p) of path p = <v0, v1, …., vk> is the sum of the weights of its
constituent edges:
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Shortest Path Properties
 Paths are directed.A shortest path must respect the direction of its edges.
 The weights are not necessarily distances. Geometric intuition can be helpful, but the
edge weights might represent time or cost.
 Not all vertices need be reachable. If t is not reachable from s, there is no path at all,
and therefore there is no shortest path from s to t.
 Negative weights introduce complications.
 Shortest paths are normally simple.
 Shortest paths are not necessarily unique.There may be multiple paths of the lowest
weight from one vertex to another; we are content to find any one of them.
 Parallel edges and self-loops may be present.
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Shortest Path: Variant
 Single-destination shortest-paths problem:
 Find a shortest path to a given destination vertex t from each vertex v.
 Reversing the direction of each edge  reduce this problem to a single-source
problem.
 Single-pair shortest-path problem:
 Find a shortest path from u to v for given vertices u and v, where source vertex is u
 All-pairs shortest-paths problem:
 Find a shortest path from u to v for every pair of vertices u and v.
 Solve this problem by running a single source algorithm once from each vertex.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Shortest Paths Tree
 A shortest-paths tree rooted at s is a directed subgraph G' = (V', E'),
whereV' ⊆V and E' ⊆ E, such that
1. V' is the set of vertices reachable from s in G,
2. G' forms a rooted tree with root s, and
3. for all v ∈ V', the unique simple path from s to v in G' is a shortest path from s
to v in G.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Shortest Paths Tree
 Shortest paths are not necessarily unique, and neither are shortest-paths trees.
 A weighted, directed graph and two shortest-paths trees with the same root.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Shortest Path Algorithms
 Bellman-Ford algorithm
 Negative weights are allowed
 Negative cycles reachable from the source are not allowed.
 Dijkstra’s algorithm
 Negative weights are not allowed
 Operations common in both algorithms:
 Initialization
 Relaxation
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Shortest Path Algorithms Initialization
 For each vertex v ∈ V, we maintain an attribute v.d, which is an upper bound on the
weight of a shortest path from source s to v.
 We call v.d a shortest-path estimate.
 We initialize the shortest-path estimates and predecessors by the following O(V)
time procedure:
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Shortest Path Algorithms Relaxation
Relaxing an edge (u, v) with weight w(u, v) = 2.The shortest-path estimate of each
vertex appears within the vertex.
(a) Because v.d > u.d + w(u, v) prior to relaxation, the value of v.d decreases.
(b) Here, v.d ≤ u.d + w(u, v) before relaxing the edge, and so the relaxation step
leaves v.d unchanged.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Shortest Path Algorithms Relaxation
 Relaxation is the only means by which shortest path estimates and predecessors
change.
 Algorithms differ in how many times they relax each edge and the order in which
they relax edges.
 Dijkstra’s algorithm and the shortest-paths algorithm for directed acyclic graphs
relax each edge exactly once.
 The Bellman-Ford algorithm relaxes each edge |V|–1 times.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Breadth First Search
BFS algorithm
is a shortest-
paths algorithm
that works on
unweighted
graphs, that is,
graphs in which
each edge has
unit weight.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
Bellman-Ford Algorithm
Bellman-Ford Algorithm
 Single-source shortest path problem
 Computes d(s, v) and .v for all v V
 Allows negative edge weights - can detect negative cycles.
 ReturnsTRUE if no negative-weight cycles are reachable from the source s
 Returns FALSE otherwise  no solution exists
Bellman-Ford Algorithm
 After initializing the d and  values of all vertices in line 1,
 The algorithm makes |V|–1 passes over the edges of the graph. Each pass is one
iteration of the for loop of lines 2–4 and consists of relaxing each edge of the
graph once.
 After making |V|–1 passes, lines 5–8 check for a negative-weight cycle and return
the appropriate Boolean value.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., &
Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
Bellman-Ford Algorithm
 Runs in time O(VE),
 Initialization takes O(V) time,
 Each |V|–1 passes over the edges takes O(V) time
 For loop takes O(E) time
 Relax will take O(VE) times
 Running time:
 O(V+VE+E) = O(VE) O(V)
O(V)
O(E)
O(E)
O(VE)
Cormen, T. H., Leiserson, C. E., Rivest, R. L., &
Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
Bellman-Ford Algorithm example
 Source is vertex s
 shaded edges indicate
predecessor values: if edge
(u, v) is shaded, then
 π .v = u
 Each pass relaxes the
edges in the order (t, x),
(t, y), (t, z), (x, t), (y, x),
(y, z), (z, x), (z, s), (s, t),
(s, y)
(a) Initialization
(b)–(e) Each successive pass
|V|-1 = 5-1 = 4 over edges
(e)The d and π values are
the final values
The Bellman-Ford algorithm
returnsTRUE Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009).
Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
Bellman-Ford Algorithm
 Each edge is relaxed |V|–1 times by making |V|-1 passes over the whole edge
set.
 To make sure that each edge is relaxed exactly |V – 1| times, it puts the edges in
an unordered list and goes over the list |V – 1| times.
0
 
 
6
5
7
7
9
s
t x
y z
8
-3
2
-4
-2
(t, x), (t, y), (t, z), (x, t), (y, x), (y, z), (z, x), (z, s), (s, t), (s, y)
George Bebis
BELLMAN-FORD(V, E, w, s)
0
 
 
6
5
7
7
9
s
t x
y z
8
-3
2
-4
-2
0
 
 
6
5
7
7
9
s
t x
y z
8
-3
2
-4
-2
E: (t, x), (t, y), (t, z), (x, t), (y, x), (y, z), (z, x), (z, s), (s, t), (s, y)
6
7
Pass 1
George Bebis
Example
0
6 
7 
6
5
7
7
9
s
t x
y z
8
-3
2
-4
-2
(t, x), (t, y), (t, z), (x, t), (y, x), (y, z), (z, x), (z, s), (s, t), (s, y)
0
6 
7 
6
5
7
7
9
s
t x
y z
8
-3
2
-4
-2
11
2
4
0
6 
7 
6
5
7
7
9
s
t x
y z
8
-3
2
-4
-2
11
2
4
2
0
6 
7 
6
5
7
7
9
s
t x
y z
8
-3
2
-4
-2
11
2
4
2
-2
Pass 1
(from previous slide)
Pass 2
Pass 3 Pass 4
George Bebis
Detecting Negative Cycles
 (perform extra test afterV-1 iterations)
for each edge (u, v)  E
do if d[v] > d[u] + w(u, v)
then return FALSE
return TRUE
0 

c
s b
2
3
-8
0 

c
s b
2
3
-8
2
5
-3 -3 2
5
c
s b
2
3
-8
-1
2
-6
Look at edge (s, b):
d[b] = -1
d[s] + w(s, b) = -4
 d[b] > d[s] + w(s, b)
1st pass 2nd pass
(s,b) (b,c) (c,s)
George Bebis
Cycles
Can shortest paths contain cycles?
 Negative-weight cycles: NO
 Shortest path is not well defined, because each iteration result in reduced shortest path
 Positive-weight cycles: NO
 Path is a tree, property of tree that tree does not have cycle
 By removing the cycle, we can get a shorter path, like we did in minimum spanning tree
 Zero-weight cycles
 No reason to use them
 Can remove them to obtain a path with same weight
George Bebis
Shortest paths in Directed Acyclic Graphs (DAG)
 Single-source Shortest paths in DAG
 Topological sort of line 1 takes O(V + E) time
 INITIALIZE line 2 takes O(V) time
 for loop of lines 3–5 makes one iteration per vertex
 for loop of lines 4–5 relaxes each edge exactly once.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
O(V+E)
O(V)
O(V)
O(E)
O(E)
Shortest
paths in
Directed
Acyclic
Graphs (DAG)
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
Dijkstra’s Algorithm
Dijkstra’s Algorithm
 Single-source shortest path problem:
 No negative-weight edges: w(u, v) > 0,  (u, v)  E
 Each edge is relaxed only once!
 Maintains two sets of vertices:
 Similar to Prim’s algorithm, which finds Minimum SpanningTree (MST)
d[v]=δ (s, v) d[v]>δ (s, v) George Bebis
Dijkstra’s Algorithm
 Line 1 initializes the d and  values in the usual way,
 Line 2 initializes the set S to the empty set.
 Line 3 initializes the min-priority queue Q to contain all the vertices inV;
Cormen, T. H., Leiserson, C. E., Rivest, R. L., &
Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
Dijkstra’s Algorithm
 While loop of lines 4–8, line 5 extracts a vertex u from Q and
 Line 6 adds it to set S, thereby maintaining the invariant.Vertex u, therefore, has
the smallest shortest-path estimate of any vertex inV - S.
 Then, lines 7–8 relax each edge, thus updating the estimate v.d and the predecessor
v.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., &
Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
Dijkstra’s Algorithm
 While loop of lines 4–8, line 5 extracts a vertex u from Q and
 Line 6 adds it to set S, thereby maintaining the invariant.Vertex u, therefore, has
the smallest shortest-path estimate of any vertex inV - S.
 Then, lines 7–8 relax each edge, thus updating the estimate v.d and the predecessor
v.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., &
Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
Dijkstra (G, w, s)
0
 
 
10
1
5
2
s
t x
y z
2 3
9
7
4 6
0
 
 
10
1
5
2
s
t x
y z
2 3
9
7
4 6
10
5
S=<> Q=<s,t,x,z,y> S=<s> Q=<y,t,x,z>
George Bebis
Example (cont.)
0
10 
5 
10
1
5
2
s
t x
y z
2 3
9
7
4 6
8 14
7
0
8 14
5 7
10
1
5
2
s
t x
y z
2 3
9
7
4 6
13
S=<s,y> Q=<z,t,x> S=<s,y,z> Q=<t,x>
George Bebis
Example (cont.)
0
8 13
5 7
10
1
5
2
s
t x
y z
2 3
9
7
4 6
9
0
8 9
5 7
10
1
5
2
s
t x
y z
2 3
9
7
4 6
S=<s,y,z,t> Q=<x> S=<s,y,z,t,x> Q=<>
George Bebis
Dijkstra’s Algorithm
 Running time: O(VlgV + ElgV) = O(ElgV)
Cormen, T. H., Leiserson, C. E., Rivest, R. L., &
Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
(V)
O(V) build min-heap
Executed O(V) times
O(lgV)
O(VlgV)
O(E) times
O(ElgV)
Dijkstra’s Algorithm
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Single Source Shortest-Paths Implementation
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Java Code Implementation for
Graph and Shortest Path
Java Code: Weighted Directed Edge
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Java Code: Edge-Weighted Digraph
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Java Code: Relaxation
 Relax(u, v, w)  relax(DirectedEdge e)
 u became v u = v = e.from()
 v became w v = w = e.to()
 w(u, v) became e.weight()
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Cormen, T. H., Leiserson, C. E., Rivest, R. L., &
Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
Java Code: Bellman-Ford algorithm
Cormen, T. H., Leiserson, C. E., Rivest, R. L., &
Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Java Code: Bellman-Ford algorithm
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Java Code: Shortest paths in DAG
DirectedAcyclic Graphs (DAG)
Cormen, T. H., Leiserson, C. E., Rivest, R. L., &
Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Java Code: Dijkstra's algorithm
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Cormen, T. H., Leiserson, C. E., Rivest, R. L.,
& Stein, C. (2009). Introduction to Algorithms
(Vol. 3, pp. 624-642). Cambridge: MIT press.
Dijkstra's algorithm: Relaxation
ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
Applications of Shortest Path
Graph or Network Theories
 Network flow: “Directed graph where each edge has a capacity and each edge
receives a flow, where the amount of flow on an edge cannot exceed the capacity of
the edge”
 Transport problem: study of optimal transportation and allocation of resources.
 Trans-shipment problem: a subgroup of transportation problems, where,
transportation may or must go through intermediate nodes, possibly changing
modes of transport
 Critical path analysis: identifying the longest dependent activities and
measuring the time required to complete a project
 PERT to analyze and represent the tasks involved in completing a given project
Complex Networks
 Non-trivial topological features in networks representing real systems
 e.g. theories: Network motifs are small subgraphs that are over-represented in the
network
 Examples of Complex networks are
 computer networks,
 biological networks,
 technological networks,
 brain networks,
 climate networks and
 social networks.
https://en.wikipedia.org/wiki/Complex_network
Complex Network analysis
 Electric power systems analysis:
 a graph consists from representing electric power aspects (e.g., transmission line
impedances)
 Biological network analysis:
 analysis of molecular networks
 visualize the nature and strength of interactions between species
 Gene Regulatory Networks (GRN), Metabolic networks, Protein-Protein Interaction,
molecular interactions
 Operations research: logistical networks, social networks, epistemological
networks
Complex Network analysis
 Computer science: graphs are used to represent networks of communication,
data organization, computational devices, the flow of computation, etc.
 Link analysis: the link structure of aWorldWideWeb, Internet, Computer Network
 website can be represented by a directed graph,
 the vertices represent web pages and directed edges represent links from one page to
another
 Social network analysis:
 graph with the structure of relationships between social entities.
 entities are persons, groups, organizations, nation states, web sites, or scholarly
publications
PERT Chart Analysis: Critical Path
 Edges represent jobs to be performed, and edge weights represent the times
required to perform particular jobs.
 If edge (u, v) enters vertex v and edge (v, x) leaves v, then job (u, v) must be
performed before job (v, x).
 A path through this dag represents a sequence of jobs that must be performed in a
particular order.A critical path is a longest path through the dag, corresponding to
the longest time to perform any sequence of jobs.Thus, the weight of a critical path
provides a lower bound on the total time to perform all the jobs.We can find a
critical path by either
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
PERT Chart Analysis: Critical path
 The longest stretch of dependent activities and measuring the time required to
complete them from start to finish.
 Activities A, B, C, D, and E comprise the critical path,
https://en.wikipedia.org/wiki/Critical_path_method
Longest path: Critical Path
 Negating the edge weights and running DAG-SHORTEST-PATHS,
or
 running DAG SHORTEST-PATHS, with the modification that we replace “∞” by
“– ∞” in line 2 of INITIALIZE-SINGLE-SOURCE and “>” by “<” in the RELAX
procedure.
Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3,
pp. 624-642). Cambridge: MIT press.
ROBERT SEDGEWICK | KEVIN
WAYNE. Algorithms 4th Edition,
https://algs4.cs.princeton.edu/44sp/
ROBERT SEDGEWICK | KEVIN
WAYNE. Algorithms 4th Edition,
https://algs4.cs.princeton.edu/44sp/
ROBERT SEDGEWICK |
KEVIN WAYNE.
Algorithms 4th Edition,
https://algs4.cs.princeton.edu/44sp/
ROBERT SEDGEWICK |
KEVIN WAYNE.
Algorithms 4th Edition,
https://algs4.cs.princeton.edu/44sp/
ROBERT SEDGEWICK |
KEVIN WAYNE.
Algorithms 4th Edition,
https://algs4.cs.princeton.edu/44sp/
ROBERT SEDGEWICK |
KEVIN WAYNE.
Algorithms 4th Edition,
https://algs4.cs.princeton.edu/44sp/
Thank You
Japanese
Hebrew
English
Merci
French
Russian
Danke
German
Grazie
Italian
Gracias
Spanish
Obrigado
Portuguese
Arabic
Simplified
Chinese
Traditional
Chinese
Tamil
Thai
Korean
https://sites.google.com/site/animeshchaturvedi07

More Related Content

What's hot

Ford fulkerson
Ford fulkersonFord fulkerson
Ford fulkersonbat coder
 
CS6702 graph theory and applications notes pdf book
CS6702 graph theory and applications notes pdf bookCS6702 graph theory and applications notes pdf book
CS6702 graph theory and applications notes pdf bookappasami
 
Bellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraqBellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraqmontaser185
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithmsSaga Valsalan
 
Floyd Warshall Algorithm
Floyd Warshall Algorithm Floyd Warshall Algorithm
Floyd Warshall Algorithm Imamul Kadir
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest pathArafat Hossan
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfShiwani Gupta
 
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 treeoneous
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmAcad
 
Chomsky & Greibach Normal Forms
Chomsky & Greibach Normal FormsChomsky & Greibach Normal Forms
Chomsky & Greibach Normal FormsRajendran
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithmRuchika Sinha
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's AlgorithmArijitDhali
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)Madhu Bala
 

What's hot (20)

Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Maximum flow
Maximum flowMaximum flow
Maximum flow
 
Ford fulkerson
Ford fulkersonFord fulkerson
Ford fulkerson
 
CS6702 graph theory and applications notes pdf book
CS6702 graph theory and applications notes pdf bookCS6702 graph theory and applications notes pdf book
CS6702 graph theory and applications notes pdf book
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Bellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraqBellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraq
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
Floyd Warshall Algorithm
Floyd Warshall Algorithm Floyd Warshall Algorithm
Floyd Warshall Algorithm
 
BISECTION METHOD
BISECTION METHODBISECTION METHOD
BISECTION METHOD
 
Kruskal’s Algorithm
Kruskal’s AlgorithmKruskal’s Algorithm
Kruskal’s Algorithm
 
graph theory
graph theory graph theory
graph theory
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdf
 
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
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithm
 
Chomsky & Greibach Normal Forms
Chomsky & Greibach Normal FormsChomsky & Greibach Normal Forms
Chomsky & Greibach Normal Forms
 
Network flows
Network flowsNetwork flows
Network flows
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 

Similar to Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java coding, and Applications

Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...Animesh Chaturvedi
 
Ppp1 Rubber Elasticity
Ppp1 Rubber ElasticityPpp1 Rubber Elasticity
Ppp1 Rubber Elasticityguest824336
 
Final Report
Final ReportFinal Report
Final ReportCan Liu
 
Generalized CDT as a scaling limit of planar maps
Generalized CDT as a scaling limit of planar mapsGeneralized CDT as a scaling limit of planar maps
Generalized CDT as a scaling limit of planar mapsTimothy Budd
 
M1 unit iv-jntuworld
M1 unit iv-jntuworldM1 unit iv-jntuworld
M1 unit iv-jntuworldmrecedu
 
22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.pptKarunaBiswas3
 
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gpchandrashekarr799
 
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
 
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...Khoa Mac Tu
 
Dr NV SRINIVASULU-Tpjrc ijaerd paper
Dr NV SRINIVASULU-Tpjrc ijaerd paperDr NV SRINIVASULU-Tpjrc ijaerd paper
Dr NV SRINIVASULU-Tpjrc ijaerd paperSRINIVASULU N V
 

Similar to Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java coding, and Applications (20)

Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
 
Floyd aaaaaa
Floyd aaaaaaFloyd aaaaaa
Floyd aaaaaa
 
DAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptxDAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptx
 
Ppp1 Rubber Elasticity
Ppp1 Rubber ElasticityPpp1 Rubber Elasticity
Ppp1 Rubber Elasticity
 
Graph 3
Graph 3Graph 3
Graph 3
 
21 All Pairs Shortest Path
21 All Pairs Shortest Path21 All Pairs Shortest Path
21 All Pairs Shortest Path
 
Problem baupc 2004
Problem baupc 2004Problem baupc 2004
Problem baupc 2004
 
Temporal graph
Temporal graphTemporal graph
Temporal graph
 
Final Report
Final ReportFinal Report
Final Report
 
Generalized CDT as a scaling limit of planar maps
Generalized CDT as a scaling limit of planar mapsGeneralized CDT as a scaling limit of planar maps
Generalized CDT as a scaling limit of planar maps
 
M1 unit iv-jntuworld
M1 unit iv-jntuworldM1 unit iv-jntuworld
M1 unit iv-jntuworld
 
22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt
 
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
 
shortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdfshortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdf
 
path
pathpath
path
 
CST 504 Graphs
CST 504 GraphsCST 504 Graphs
CST 504 Graphs
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
 
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
 
2019 Triangle Machine Learning Day - Machine Learning for 3D Imaging - Sayan ...
2019 Triangle Machine Learning Day - Machine Learning for 3D Imaging - Sayan ...2019 Triangle Machine Learning Day - Machine Learning for 3D Imaging - Sayan ...
2019 Triangle Machine Learning Day - Machine Learning for 3D Imaging - Sayan ...
 
Dr NV SRINIVASULU-Tpjrc ijaerd paper
Dr NV SRINIVASULU-Tpjrc ijaerd paperDr NV SRINIVASULU-Tpjrc ijaerd paper
Dr NV SRINIVASULU-Tpjrc ijaerd paper
 

More from Animesh Chaturvedi

Cloud platforms and frameworks
Cloud platforms and frameworksCloud platforms and frameworks
Cloud platforms and frameworksAnimesh Chaturvedi
 
Cloud service lifecycle management
Cloud service lifecycle managementCloud service lifecycle management
Cloud service lifecycle managementAnimesh Chaturvedi
 
Graph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersGraph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersAnimesh Chaturvedi
 
Advance Systems Engineering Topics
Advance Systems Engineering TopicsAdvance Systems Engineering Topics
Advance Systems Engineering TopicsAnimesh Chaturvedi
 
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
 
System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)Animesh Chaturvedi
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsAnimesh Chaturvedi
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solutionAnimesh Chaturvedi
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2Animesh Chaturvedi
 
System requirements engineering
System requirements engineeringSystem requirements engineering
System requirements engineeringAnimesh Chaturvedi
 
Introduction to Systems Engineering
Introduction to Systems EngineeringIntroduction to Systems Engineering
Introduction to Systems EngineeringAnimesh Chaturvedi
 
Big Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingBig Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingAnimesh Chaturvedi
 
Cloud Platforms and Frameworks
Cloud Platforms and FrameworksCloud Platforms and Frameworks
Cloud Platforms and FrameworksAnimesh Chaturvedi
 
Cloud Service Life-cycle Management
Cloud Service Life-cycle ManagementCloud Service Life-cycle Management
Cloud Service Life-cycle ManagementAnimesh Chaturvedi
 
Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Animesh Chaturvedi
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expressionAnimesh Chaturvedi
 

More from Animesh Chaturvedi (20)

Cloud Platforms & Frameworks
Cloud Platforms & FrameworksCloud Platforms & Frameworks
Cloud Platforms & Frameworks
 
Cloud platforms and frameworks
Cloud platforms and frameworksCloud platforms and frameworks
Cloud platforms and frameworks
 
Cloud service lifecycle management
Cloud service lifecycle managementCloud service lifecycle management
Cloud service lifecycle management
 
Graph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersGraph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answers
 
Advance Systems Engineering Topics
Advance Systems Engineering TopicsAdvance Systems Engineering Topics
Advance Systems Engineering Topics
 
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
 
System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
 
System requirements engineering
System requirements engineeringSystem requirements engineering
System requirements engineering
 
Informatics systems
Informatics systemsInformatics systems
Informatics systems
 
Introduction to Systems Engineering
Introduction to Systems EngineeringIntroduction to Systems Engineering
Introduction to Systems Engineering
 
Big Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingBig Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computing
 
Cloud Platforms and Frameworks
Cloud Platforms and FrameworksCloud Platforms and Frameworks
Cloud Platforms and Frameworks
 
Cloud Service Life-cycle Management
Cloud Service Life-cycle ManagementCloud Service Life-cycle Management
Cloud Service Life-cycle Management
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
 
Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
 

Recently uploaded

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
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
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
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
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 Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
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
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
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
 

Recently uploaded (20)

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
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
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
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
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
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
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 Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
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...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
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
 

Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java coding, and Applications

  • 1. Shortest Path, Bellman-Ford algorithm, Dijkstra’s algorithm, and Applications by Dr.Animesh Chaturvedi Assistant Professor: LNMIIT Jaipur Post Doctorate: King’s College London &TheAlanTuring Institute PhD: IIT Indore
  • 3.  Adjacency-list andAdjacency-matrix representation of undirected graph G with 5 vertices and 7 edges.  Adjacency-list andAdjacency-matrix representations of a directed graph G with 6 vertices and 8 edges. Graph representations
  • 4. Shortest Path  Given a road map of the India on which the distance between each pair of adjacent intersections is marked between route from Delhi to Mumbai, how can you find the shortest possible route?  To examine an enormous number of possibilities, most of which are simply not worth considering!  Model the road map as a graph vertices represent intersections, edges represent road segments between intersections, and edge weights represent road distances.  For other examples weights can represent metrics other than distances, such as time, cost, penalties, loss, or any other quantity that accumulates. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 5. Shortest Path  In a shortest-paths problem, given a weighted directed graph G = (V, E) with edges mapped to real-valued weights.  The weight w(p) of path p = <v0, v1, …., vk> is the sum of the weights of its constituent edges: Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 6. Shortest Path Properties  Paths are directed.A shortest path must respect the direction of its edges.  The weights are not necessarily distances. Geometric intuition can be helpful, but the edge weights might represent time or cost.  Not all vertices need be reachable. If t is not reachable from s, there is no path at all, and therefore there is no shortest path from s to t.  Negative weights introduce complications.  Shortest paths are normally simple.  Shortest paths are not necessarily unique.There may be multiple paths of the lowest weight from one vertex to another; we are content to find any one of them.  Parallel edges and self-loops may be present. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 7. Shortest Path: Variant  Single-destination shortest-paths problem:  Find a shortest path to a given destination vertex t from each vertex v.  Reversing the direction of each edge  reduce this problem to a single-source problem.  Single-pair shortest-path problem:  Find a shortest path from u to v for given vertices u and v, where source vertex is u  All-pairs shortest-paths problem:  Find a shortest path from u to v for every pair of vertices u and v.  Solve this problem by running a single source algorithm once from each vertex. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 8. Shortest Paths Tree  A shortest-paths tree rooted at s is a directed subgraph G' = (V', E'), whereV' ⊆V and E' ⊆ E, such that 1. V' is the set of vertices reachable from s in G, 2. G' forms a rooted tree with root s, and 3. for all v ∈ V', the unique simple path from s to v in G' is a shortest path from s to v in G. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 9. Shortest Paths Tree  Shortest paths are not necessarily unique, and neither are shortest-paths trees.  A weighted, directed graph and two shortest-paths trees with the same root. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 10. Shortest Path Algorithms  Bellman-Ford algorithm  Negative weights are allowed  Negative cycles reachable from the source are not allowed.  Dijkstra’s algorithm  Negative weights are not allowed  Operations common in both algorithms:  Initialization  Relaxation Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 11. Shortest Path Algorithms Initialization  For each vertex v ∈ V, we maintain an attribute v.d, which is an upper bound on the weight of a shortest path from source s to v.  We call v.d a shortest-path estimate.  We initialize the shortest-path estimates and predecessors by the following O(V) time procedure: Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 12. Shortest Path Algorithms Relaxation Relaxing an edge (u, v) with weight w(u, v) = 2.The shortest-path estimate of each vertex appears within the vertex. (a) Because v.d > u.d + w(u, v) prior to relaxation, the value of v.d decreases. (b) Here, v.d ≤ u.d + w(u, v) before relaxing the edge, and so the relaxation step leaves v.d unchanged. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 13. Shortest Path Algorithms Relaxation  Relaxation is the only means by which shortest path estimates and predecessors change.  Algorithms differ in how many times they relax each edge and the order in which they relax edges.  Dijkstra’s algorithm and the shortest-paths algorithm for directed acyclic graphs relax each edge exactly once.  The Bellman-Ford algorithm relaxes each edge |V|–1 times. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 14. Breadth First Search BFS algorithm is a shortest- paths algorithm that works on unweighted graphs, that is, graphs in which each edge has unit weight. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 16. Bellman-Ford Algorithm  Single-source shortest path problem  Computes d(s, v) and .v for all v V  Allows negative edge weights - can detect negative cycles.  ReturnsTRUE if no negative-weight cycles are reachable from the source s  Returns FALSE otherwise  no solution exists
  • 17. Bellman-Ford Algorithm  After initializing the d and  values of all vertices in line 1,  The algorithm makes |V|–1 passes over the edges of the graph. Each pass is one iteration of the for loop of lines 2–4 and consists of relaxing each edge of the graph once.  After making |V|–1 passes, lines 5–8 check for a negative-weight cycle and return the appropriate Boolean value. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 18. Bellman-Ford Algorithm  Runs in time O(VE),  Initialization takes O(V) time,  Each |V|–1 passes over the edges takes O(V) time  For loop takes O(E) time  Relax will take O(VE) times  Running time:  O(V+VE+E) = O(VE) O(V) O(V) O(E) O(E) O(VE) Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 19. Bellman-Ford Algorithm example  Source is vertex s  shaded edges indicate predecessor values: if edge (u, v) is shaded, then  π .v = u  Each pass relaxes the edges in the order (t, x), (t, y), (t, z), (x, t), (y, x), (y, z), (z, x), (z, s), (s, t), (s, y) (a) Initialization (b)–(e) Each successive pass |V|-1 = 5-1 = 4 over edges (e)The d and π values are the final values The Bellman-Ford algorithm returnsTRUE Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 20. Bellman-Ford Algorithm  Each edge is relaxed |V|–1 times by making |V|-1 passes over the whole edge set.  To make sure that each edge is relaxed exactly |V – 1| times, it puts the edges in an unordered list and goes over the list |V – 1| times. 0     6 5 7 7 9 s t x y z 8 -3 2 -4 -2 (t, x), (t, y), (t, z), (x, t), (y, x), (y, z), (z, x), (z, s), (s, t), (s, y) George Bebis
  • 21. BELLMAN-FORD(V, E, w, s) 0     6 5 7 7 9 s t x y z 8 -3 2 -4 -2 0     6 5 7 7 9 s t x y z 8 -3 2 -4 -2 E: (t, x), (t, y), (t, z), (x, t), (y, x), (y, z), (z, x), (z, s), (s, t), (s, y) 6 7 Pass 1 George Bebis
  • 22. Example 0 6  7  6 5 7 7 9 s t x y z 8 -3 2 -4 -2 (t, x), (t, y), (t, z), (x, t), (y, x), (y, z), (z, x), (z, s), (s, t), (s, y) 0 6  7  6 5 7 7 9 s t x y z 8 -3 2 -4 -2 11 2 4 0 6  7  6 5 7 7 9 s t x y z 8 -3 2 -4 -2 11 2 4 2 0 6  7  6 5 7 7 9 s t x y z 8 -3 2 -4 -2 11 2 4 2 -2 Pass 1 (from previous slide) Pass 2 Pass 3 Pass 4 George Bebis
  • 23. Detecting Negative Cycles  (perform extra test afterV-1 iterations) for each edge (u, v)  E do if d[v] > d[u] + w(u, v) then return FALSE return TRUE 0   c s b 2 3 -8 0   c s b 2 3 -8 2 5 -3 -3 2 5 c s b 2 3 -8 -1 2 -6 Look at edge (s, b): d[b] = -1 d[s] + w(s, b) = -4  d[b] > d[s] + w(s, b) 1st pass 2nd pass (s,b) (b,c) (c,s) George Bebis
  • 24. Cycles Can shortest paths contain cycles?  Negative-weight cycles: NO  Shortest path is not well defined, because each iteration result in reduced shortest path  Positive-weight cycles: NO  Path is a tree, property of tree that tree does not have cycle  By removing the cycle, we can get a shorter path, like we did in minimum spanning tree  Zero-weight cycles  No reason to use them  Can remove them to obtain a path with same weight George Bebis
  • 25. Shortest paths in Directed Acyclic Graphs (DAG)  Single-source Shortest paths in DAG  Topological sort of line 1 takes O(V + E) time  INITIALIZE line 2 takes O(V) time  for loop of lines 3–5 makes one iteration per vertex  for loop of lines 4–5 relaxes each edge exactly once. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press. O(V+E) O(V) O(V) O(E) O(E)
  • 26. Shortest paths in Directed Acyclic Graphs (DAG) Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 28. Dijkstra’s Algorithm  Single-source shortest path problem:  No negative-weight edges: w(u, v) > 0,  (u, v)  E  Each edge is relaxed only once!  Maintains two sets of vertices:  Similar to Prim’s algorithm, which finds Minimum SpanningTree (MST) d[v]=δ (s, v) d[v]>δ (s, v) George Bebis
  • 29. Dijkstra’s Algorithm  Line 1 initializes the d and  values in the usual way,  Line 2 initializes the set S to the empty set.  Line 3 initializes the min-priority queue Q to contain all the vertices inV; Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 30. Dijkstra’s Algorithm  While loop of lines 4–8, line 5 extracts a vertex u from Q and  Line 6 adds it to set S, thereby maintaining the invariant.Vertex u, therefore, has the smallest shortest-path estimate of any vertex inV - S.  Then, lines 7–8 relax each edge, thus updating the estimate v.d and the predecessor v. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 31. Dijkstra’s Algorithm  While loop of lines 4–8, line 5 extracts a vertex u from Q and  Line 6 adds it to set S, thereby maintaining the invariant.Vertex u, therefore, has the smallest shortest-path estimate of any vertex inV - S.  Then, lines 7–8 relax each edge, thus updating the estimate v.d and the predecessor v. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43. Dijkstra (G, w, s) 0     10 1 5 2 s t x y z 2 3 9 7 4 6 0     10 1 5 2 s t x y z 2 3 9 7 4 6 10 5 S=<> Q=<s,t,x,z,y> S=<s> Q=<y,t,x,z> George Bebis
  • 44. Example (cont.) 0 10  5  10 1 5 2 s t x y z 2 3 9 7 4 6 8 14 7 0 8 14 5 7 10 1 5 2 s t x y z 2 3 9 7 4 6 13 S=<s,y> Q=<z,t,x> S=<s,y,z> Q=<t,x> George Bebis
  • 45. Example (cont.) 0 8 13 5 7 10 1 5 2 s t x y z 2 3 9 7 4 6 9 0 8 9 5 7 10 1 5 2 s t x y z 2 3 9 7 4 6 S=<s,y,z,t> Q=<x> S=<s,y,z,t,x> Q=<> George Bebis
  • 46. Dijkstra’s Algorithm  Running time: O(VlgV + ElgV) = O(ElgV) Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press. (V) O(V) build min-heap Executed O(V) times O(lgV) O(VlgV) O(E) times O(ElgV)
  • 47. Dijkstra’s Algorithm ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 48. Single Source Shortest-Paths Implementation ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 49. Java Code Implementation for Graph and Shortest Path
  • 50. Java Code: Weighted Directed Edge ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 51. Java Code: Edge-Weighted Digraph ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 52. Java Code: Relaxation  Relax(u, v, w)  relax(DirectedEdge e)  u became v u = v = e.from()  v became w v = w = e.to()  w(u, v) became e.weight() ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/ Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 53. Java Code: Bellman-Ford algorithm Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 54. Java Code: Bellman-Ford algorithm Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 55. Java Code: Shortest paths in DAG DirectedAcyclic Graphs (DAG) Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 56. Java Code: Dijkstra's algorithm ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/ Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 57. Dijkstra's algorithm: Relaxation ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 59. Graph or Network Theories  Network flow: “Directed graph where each edge has a capacity and each edge receives a flow, where the amount of flow on an edge cannot exceed the capacity of the edge”  Transport problem: study of optimal transportation and allocation of resources.  Trans-shipment problem: a subgroup of transportation problems, where, transportation may or must go through intermediate nodes, possibly changing modes of transport  Critical path analysis: identifying the longest dependent activities and measuring the time required to complete a project  PERT to analyze and represent the tasks involved in completing a given project
  • 60. Complex Networks  Non-trivial topological features in networks representing real systems  e.g. theories: Network motifs are small subgraphs that are over-represented in the network  Examples of Complex networks are  computer networks,  biological networks,  technological networks,  brain networks,  climate networks and  social networks. https://en.wikipedia.org/wiki/Complex_network
  • 61. Complex Network analysis  Electric power systems analysis:  a graph consists from representing electric power aspects (e.g., transmission line impedances)  Biological network analysis:  analysis of molecular networks  visualize the nature and strength of interactions between species  Gene Regulatory Networks (GRN), Metabolic networks, Protein-Protein Interaction, molecular interactions  Operations research: logistical networks, social networks, epistemological networks
  • 62. Complex Network analysis  Computer science: graphs are used to represent networks of communication, data organization, computational devices, the flow of computation, etc.  Link analysis: the link structure of aWorldWideWeb, Internet, Computer Network  website can be represented by a directed graph,  the vertices represent web pages and directed edges represent links from one page to another  Social network analysis:  graph with the structure of relationships between social entities.  entities are persons, groups, organizations, nation states, web sites, or scholarly publications
  • 63. PERT Chart Analysis: Critical Path  Edges represent jobs to be performed, and edge weights represent the times required to perform particular jobs.  If edge (u, v) enters vertex v and edge (v, x) leaves v, then job (u, v) must be performed before job (v, x).  A path through this dag represents a sequence of jobs that must be performed in a particular order.A critical path is a longest path through the dag, corresponding to the longest time to perform any sequence of jobs.Thus, the weight of a critical path provides a lower bound on the total time to perform all the jobs.We can find a critical path by either Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 64. PERT Chart Analysis: Critical path  The longest stretch of dependent activities and measuring the time required to complete them from start to finish.  Activities A, B, C, D, and E comprise the critical path, https://en.wikipedia.org/wiki/Critical_path_method
  • 65. Longest path: Critical Path  Negating the edge weights and running DAG-SHORTEST-PATHS, or  running DAG SHORTEST-PATHS, with the modification that we replace “∞” by “– ∞” in line 2 of INITIALIZE-SINGLE-SOURCE and “>” by “<” in the RELAX procedure. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (Vol. 3, pp. 624-642). Cambridge: MIT press.
  • 66. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 67. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 68. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 69. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 70. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/
  • 71. ROBERT SEDGEWICK | KEVIN WAYNE. Algorithms 4th Edition, https://algs4.cs.princeton.edu/44sp/