CS221 ShortestPath
CS221 ShortestPath
1
Route Calculation
Iteration N D2 D3 D4 D5 D6
Initial {1} 3 2 5
1 {1,3} 3 2 4 3
2 {1,2,3} 3 2 4 7 3
3 {1,2,3,6} 3 2 4 5 3
4 {1,2,3,4,6} 3 2 4 5 3
5 {1,2,3,4,5,6} 3 2 4 5 3
Shortest Paths in Dijkstra’s Algorithm
2 3 1 2 3 1
1 1
6 6
5 2 5 2
3 3
1 4 2 1 4 2
3 3
2 2
4 5 4 5
2 3 1 2 3 1
1 1
6 6
5 2 5 2
3 3
1 4 2 1 4 2
3 3
2 2
4 5 4 5
2 3 1 2 3 1
1 1
6 6
5 2 5 2
3 3
1 4 2 1 4 2
3 3
2 2
4 5 4 5
7777777777777
Step start N D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E) D(F),p(F)
0 A 2,A 5,A 1,A infinity infinity
1 AD 2,A 4,D 2,D infinity
2 ADE 2,A 3,E 4,E
3 ADEB 3,E 4,E
Dijkstra’s algorithm: example
4 ADEBC 4,E
5 ADEBCF
5
3
B C 5
2
A 2 1 F
3
1 2
D E
1
ALL PAIRS SHORTEST PATH
So far, we have discussed the problem of finding
the shortest paths, starting from a specific node .
How about finding the shorted path between
every possible pair of nodes in a graph?
Which algorithm can be used?
Dijkstra’s algorithm can be used
Call
the Dijkstra’s algorithm by setting each node as the
source node, one by one
Any Other solution?
Floyd -Warshal Algorithm can be used instead..