2. 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.
3. 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
4. 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.
5. 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
6. 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)
7. 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
8. 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
18. 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|