krishna Acharjee
Dijkstras Algorithm
d4
4
d3 d2
3 2
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?
d5
d4
4
d3 d2
3 2
d5
Next loop: If (d3 + w32 < d2) then w32 we have found a shorter path from 1 to 2, that is d3+w32 not d2. else d2 remains as shortest distance from 1 to 2.
d4
4
d3 d2
3 2
w32
Each loop: We find shortest path from start node to one of the node. Continue until we hit our target node.
d5
1
2 2 15
15
PROBLEM
2
6 1
6
17 4
3 4
3 1
0 1
0 2
0 3
0 4
0 5
0 6
current 0
6
d=0
1
2 15 2 6 3
15
2
1
6
17 4
3 4
1
0 1
0 2
0 3
0 4
0 5
0 6
current 0
6
d=0
1
2 15 2 6 3
15
2
1
6
17 4
3 4
1
6
d=0
d=2
1
2 15
15
2 6 3
2
1
d=15
6
17 4
3 4
1
0 1 1 2
0 2
0 3
0 4
0 5
0 0 current 1 6 15
6
d=0
d=2
1
2
d=4
15
15
2 6
d=8
2
1
d=15
6
17 4
3
3
4
1
0 1 1 2
1 1 2 4
1 0 3 8
0 4
0 5
0 0 current 2 6 15
6
d=0
d=2
1
2
d=4
15
15
2 6 3
d=10
2
1
6
17 4
3
d=5
4
1
6
d=0
d=2
1
2
d=4
15
15
2 6 3
2
1
d=10
6
17 4
3
d=5
4
1
0 1 1 2
1 1 2 4
2 1 3 5
0 4
0 5
2 0 current 3 6 10
6
d=0
d=2
1
2
d=4
15
15
2 6 3
2
1
d=10
6
17 4
3
d=5
4
1
5
d=8
0 1 1 2
1 1 2 4
2 1 3 5
0 4
3 1 5 8
2 0 current 5 6 10
d=10
National Institute of Science & Technology
5 4 17
15
6
15 6 2
4
1
d=9
d=0
0
2
1
d=2
5
3 1
d=8
d=4
d=5
0 1 1 2
1 1 2 4
2 1 3 5
5 1 4 9
3 1 5 8
2 0 current 4 6 10
d=10
National Institute of Science & Technology
5 4 17
15
6
15 6 2
4
1
d=9
d=0
0
2
1
d=2
5
3 1
d=8
d=4
d=5
0 1 1 2
1 1 2 4
2 1 3 5
5 1 4 9
3 1 5 8
2 1 current 6 6 10
STOP
0 1 1 2
1 1 2 4
2 1 3 5
5 1 4 9
3 1 5 8
2 1 6 10
SHORTEST PATHS
THANK YOU