087-dijkstra’s algorithm
TRANSCRIPT
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 1/24
1krishna Acharjee
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
Dijkstra’sAlgorithm
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 2/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
1
4
2
5
3
d4
d3
d2
d5
Here, d3 is the smallest of the 4
distances.
Then from 1 to 2 ,SHORTEST
PATH is d2.
If there is an edge from 3 to 2,
then d2 is the shortest path or
not?
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 3/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
1
4
2
5
3
d4
d3
d2
d5
Next loop:If
(d3 + w32 < d2)
then
we have found a shorter pathfrom 1 to 2, that is d3+w32 not
d2.
else
d2 remains as shortestdistance from 1 to 2.
w32
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 4/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
1
4
2
5
3
d4
d3
d2
d5
Each loop:
We find shortest path fromstart node to one of the
node.
Continue until we hit our
target node.
w32
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 5/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
0
1
2
6
4
5
3
2
2
1
3
6
6
15 117
5
415
PROBLEM
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 6/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
prev
checked0 0 0 0 0 0 0 current 0
vertex 0 1 2 3 4 5 6∞ ∞ ∞ ∞ ∞ ∞
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 7/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
0
1
2
64
5
3
2
2
1
3
6
6
151
17
5
415
d=0
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 8/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
prev
checked 1 0 0 0 0 0 0 current 0
vertex 0 1 2 3 4 5 6
0 ∞ ∞ ∞ ∞ ∞ ∞
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 9/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
0
1
2
64
5
3
2
2
1
3
6
6
151
17
5
415
d=0
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 10/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
0
1
2
64
5
3
2
2
1
3
6
6
151
17
5
415
d=0
d=2
d=15
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 11/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
prev 0 0
checked1 1 0 0 0 0 0 current 1
vertex 0 1 2 3 4 5 6
0 2 ∞ ∞ ∞ ∞ 15
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 12/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
0
1
2
64
5
3
2
2
1
3
6
6
151
17
5
415
d=0
d=2
d=4
d=15
d=8
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 13/24
NationalIn
stit u
teofScien
ce&
Tec
hnolo
gy
prev 0 1 1 0
checked1 1 1 0 0 0 0 current 2
vertex 0 1 2 3 4 5 6
0 2 4 8 ∞ ∞ 15
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 14/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
0
1
2
64
5
3
2
2
1
3
6
6
151
17
5
415
d=0
d=2
d=4
d=10
d=5
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 15/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
0
1
2
64
5
3
2
2
1
3
6
6
151
17
5
415
d=0
d=2
d=4
d=5
d=10
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 16/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
prev 0 1 2 2
checked1 1 1 1 0 0 0 current 3
vertex 0 1 2 3 4 5 6
0 2 4 5 ∞ ∞ 10
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 17/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
0
1
2
64
5
3
2
2
1
3
6
6
151
17
5
415
d=0
d=2
d=4
d=5
d=10
d=8
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 18/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
prev 0 1 2 3 2
checked1 1 1 1 0 1 0 current 5
vertex 0 1 2 3 4 5 6
0 2 4 5 ∞ 8 10
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 19/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
0
1
2
64
5
3
2
2
1
3
6
6
151
17
5
415
d=0
d=2
d=4
d=5
d=10
d=8
d=9
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 20/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
prev 0 1 2 5 3 2
checked1 1 1 1 1 1 0 current 4
vertex 0 1 2 3 4 5 6
0 2 4 5 9 8 10
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 21/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
0
1
2
64
5
3
2
2
1
3
6
6
151
17
5
415
d=0
d=2
d=4
d=5
d=10
d=8
d=9
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 22/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
STOP
prev 0 1 2 5 3 2
checked1 1 1 1 1 1 1 current 6
vertex 0 1 2 3 4 5 6
0 2 4 5 9 8 10
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 23/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
SHORTEST PATHS
prev 0 1 2 5 3 2checked1 1 1 1 1 1 1
vertex 0 1 2 3 4 5 6
0 2 4 5 9 8 10
8/4/2019 087-Dijkstra’s Algorithm
http://slidepdf.com/reader/full/087-dijkstras-algorithm 24/24
NationalIn
stit u
teofScienc
e&
Tec
hnolo
gy
THANK YOU