Single pair shortest path
problem
MD Tanvir Anwoar & Shajedur Rahman
Introduction:
In graph theory, the shortest path problem is the problem of finding a path
between two vertices (or nodes) in a graph such that the sum of the weights
of its constituent edges is minimized.
This is analogous to the problem of finding the shortest path between two
intersections on a road map: the graph's vertices correspond to intersections
and the edges correspond to road segments, each weighted by the length of
its road segment.
Application:
* The traffic and length of the highways are path weights.
* Vehicle routing problem solving
* Solving network design problem
* In video games, these algorithms are frequently used to find the shortest
path between two points on a map
Purpose of the problem solving:
* Improve Quality of the service, Reducing time and cost
Problem solving methods :
Dijkstra Algorithm :
a. All edge weights should be non-negative
b. Each iteration of Dijkstra takes O(n^2) for array-based or O(m log n)
for heap-based
c. Total complexity is either O(n^3) or O(mn log n)
d. This is a case where just repeatedly using a solution to a simpler
problem works out fine.
Problem solving methods :
Bellman-Ford Algorithm:
a. If some edge weights are negative
b. It has complexity O(nm) for a single source
c. Total sources solution is O(n^2 m), which is O(n4) for dense graphs
Problem solving methods :
Floyd-Warshall Algorithm :
a. If some edge weights are negative
b. Dynamic programming solution to compute all sources shortest paths
c. Works with negative weights (or without) – we assume no negative cycles
d. Complexity O(n^3)
Floyd-Warshall Algorithm
1. Graph should be directed
2. It may contain negative edges but no negative cycle
3. Find the shortest path between all the pairs of nodes

A

B
Floyd-Warshall Algorithm
1. Graph should be directed
2. It may contain negative edges but no negative cycle
3. Find the shortest path between all the pairs of nodes

-2
A

B

-1
Floyd-Warshall Algorithm
Example :

1

2

4

3
Floyd-Warshall Algorithm
Example :

1

4

D

1
1,4

=

2

3
Floyd-Warshall Algorithm
Example :

1

4

D

1
1,4

2

3

= 1 ,2,4
Floyd-Warshall Algorithm
Example :

1

4

D

1
1,4

2

3

= 1 ,2,4 ; 1,4
Floyd-Warshall Algorithm
matrix formation :

D

(k)

{ min (D
if k>= 1

(k-1)

(I,j)

=

(I,j))

,

D

(k-1)
(I,k )

+

D

(k-1)
(k,j)

}
Floyd-Warshall Algorithm
matrix formation :

3
1

2

-4

7

4

8

5

3

1
2
6

4

-5

0
X
X
2
X

3
0
4
X
X

D(0)
8 X
X 1
0 X
-5 1
X 0

-4
7
-4
7
0
Floyd-Warshall Algorithm
matrix formation :

3
1

2

-4

7

4

8

5

3

1

0
X
X
2
X

3
0
4
X
X

D(0)
8 X
X 11
0 X
-5 1
X 0

2
6

D

(0)

4

-5

(2,4)

=1

-4
7
-4
7
0
Floyd-Warshall Algorithm
matrix formation :

3
1

2

-4

7

4

8

5

3

1
2
6

0
X
X
2
X

3
0
4
5
X

D(1)
8 X
X 1
0 X
-5 0
X 6

-4
7
X
-2
-2
0

Adjacency Matrix
4

-5

D

(1)
(4,5)

= -2
Floyd-Warshall Algorithm
matrix formation :

3
1

2

-4

7

4

8

5

3

1
2
6

0
3
7
2
8

1
0
4
-1
5

D(5)
-3 2
-4 1
-4
0 5
-5 0
1 6

-4
-1
3
-2
0

Adjacency Matrix
4

-5

D

(5)
(2,3)

= -4
Floyd-Warshall Algorithm
Pseudocode:
1. For i=1 to |V| do
2.
For j=1 to |V| do
3.
S[i,j,0] = w(i,j)
4. For k=1 to |V| do
5.
For i=1 to |V| do
6.
For j=1 to |V| do
7.
S[i,j,k] = min {
8.
S[i,j,k-1],
9.
S[i,k,k-1]+S[k,j,k-1]
}
10. Return S[:,:,n]
# return 2d array with n = |V|
Floyd-Warshall Algorithm

More Related Content

PPTX
Shortest path algorithm
PPT
Single source stortest path bellman ford and dijkstra
PPTX
Dijkstra’s algorithm
PDF
Context-Aware Recommender System Based on Boolean Matrix Factorisation
PDF
2-rankings of Graphs
PPT
The Floyd–Warshall algorithm
PDF
20320140501020
PDF
Kumegawa russia
Shortest path algorithm
Single source stortest path bellman ford and dijkstra
Dijkstra’s algorithm
Context-Aware Recommender System Based on Boolean Matrix Factorisation
2-rankings of Graphs
The Floyd–Warshall algorithm
20320140501020
Kumegawa russia

What's hot (19)

PPTX
Find Transitive Closure Using Floyd-Warshall Algorithm
PPTX
Path based Algorithms(Term Paper)
PDF
A Note on TopicRNN
PDF
A Note on Latent LSTM Allocation
PPT
Lecture 3 tangent & velocity problems
PDF
Algorithms explained
PDF
Joint CSI Estimation, Beamforming and Scheduling Design for Wideband Massive ...
PDF
14 - 08 Feb - Dynamic Programming
PDF
A One-Pass Triclustering Approach: Is There any Room for Big Data?
PPT
Bellman Ford's Algorithm
PDF
Incremental and parallel computation of structural graph summaries for evolvi...
PPT
Bellmanford
PPTX
PPT
Prim Algorithm and kruskal algorithm
PDF
The Fundamental Solution of an Extension to a Generalized Laplace Equation
PDF
Path Contraction Faster than 2^n
PDF
19 Minimum Spanning Trees
PPT
Price of anarchy is independent of network topology
PDF
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
Find Transitive Closure Using Floyd-Warshall Algorithm
Path based Algorithms(Term Paper)
A Note on TopicRNN
A Note on Latent LSTM Allocation
Lecture 3 tangent & velocity problems
Algorithms explained
Joint CSI Estimation, Beamforming and Scheduling Design for Wideband Massive ...
14 - 08 Feb - Dynamic Programming
A One-Pass Triclustering Approach: Is There any Room for Big Data?
Bellman Ford's Algorithm
Incremental and parallel computation of structural graph summaries for evolvi...
Bellmanford
Prim Algorithm and kruskal algorithm
The Fundamental Solution of an Extension to a Generalized Laplace Equation
Path Contraction Faster than 2^n
19 Minimum Spanning Trees
Price of anarchy is independent of network topology
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
Ad

Viewers also liked (8)

PPT
Inroduction_To_Algorithms_Lect14
PPT
Top-k shortest path
PDF
Shortest Path in Graph
PPTX
Dijkstra's algorithm
PDF
All pairs shortest path algorithm
PDF
Visual Design with Data
PDF
3 Things Every Sales Team Needs to Be Thinking About in 2017
PDF
How to Become a Thought Leader in Your Niche
Inroduction_To_Algorithms_Lect14
Top-k shortest path
Shortest Path in Graph
Dijkstra's algorithm
All pairs shortest path algorithm
Visual Design with Data
3 Things Every Sales Team Needs to Be Thinking About in 2017
How to Become a Thought Leader in Your Niche
Ad

Similar to Spsp fw (20)

PPTX
DAA_Presentation - Copy.pptx
PDF
White Grey Minimalist Geometric Project Presentation.pdf
PPTX
Randomized algorithms all pairs shortest path
PPT
Lec-35Graph - Graph - Copy in Data Structure
PDF
shortestpathalgorithm-180109112405 (1).pdf
PDF
Djikstra’s Algorithm. Approach to shortest path algorithm with greedy method
PPT
Shortest path
PPTX
Data structure and algorithm
PPT
Chapter 26 aoa
PDF
04 greedyalgorithmsii 2x2
PDF
My presentation all shortestpath
PPTX
DIJKSTRA_123.pptx
PPTX
Ds presentation
PPTX
Potential Uses of the Floyd-Warshall Algorithm as appropriate
PPT
The Floyd-Warshall of design and analysis of Algorithm.ppt
PPTX
Floyd warshall algorithm and it's applications
PPTX
Shortest Path Algorithm
PPTX
Prims Algorithm, Kruskals algorithm, Dijkstra’s Algorithm
DOCX
Shortest Path Problem.docx
PDF
DS & Algo 4 - Graph and Shortest Path Search
DAA_Presentation - Copy.pptx
White Grey Minimalist Geometric Project Presentation.pdf
Randomized algorithms all pairs shortest path
Lec-35Graph - Graph - Copy in Data Structure
shortestpathalgorithm-180109112405 (1).pdf
Djikstra’s Algorithm. Approach to shortest path algorithm with greedy method
Shortest path
Data structure and algorithm
Chapter 26 aoa
04 greedyalgorithmsii 2x2
My presentation all shortestpath
DIJKSTRA_123.pptx
Ds presentation
Potential Uses of the Floyd-Warshall Algorithm as appropriate
The Floyd-Warshall of design and analysis of Algorithm.ppt
Floyd warshall algorithm and it's applications
Shortest Path Algorithm
Prims Algorithm, Kruskals algorithm, Dijkstra’s Algorithm
Shortest Path Problem.docx
DS & Algo 4 - Graph and Shortest Path Search

Recently uploaded (20)

PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
The various Industrial Revolutions .pptx
PPTX
Microsoft Excel 365/2024 Beginner's training
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPT
Geologic Time for studying geology for geologist
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPT
What is a Computer? Input Devices /output devices
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PPTX
2018-HIPAA-Renewal-Training for executives
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
Configure Apache Mutual Authentication
PPTX
Modernising the Digital Integration Hub
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
Abstractive summarization using multilingual text-to-text transfer transforme...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
The various Industrial Revolutions .pptx
Microsoft Excel 365/2024 Beginner's training
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
A comparative study of natural language inference in Swahili using monolingua...
Geologic Time for studying geology for geologist
UiPath Agentic Automation session 1: RPA to Agents
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
What is a Computer? Input Devices /output devices
sbt 2.0: go big (Scala Days 2025 edition)
NewMind AI Weekly Chronicles – August ’25 Week III
A contest of sentiment analysis: k-nearest neighbor versus neural network
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
2018-HIPAA-Renewal-Training for executives
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Configure Apache Mutual Authentication
Modernising the Digital Integration Hub
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
Abstractive summarization using multilingual text-to-text transfer transforme...
sustainability-14-14877-v2.pddhzftheheeeee

Spsp fw