37-Link State-Dijkstra Algorithm-28-10-2023
37-Link State-Dijkstra Algorithm-28-10-2023
z
w
x
s z'
w"
x'
Dijkstra’s algorithm
• N: set of nodes for which shortest path already found
• Initialization: (Start with source node s)
• N = {s}, Ds = 0, “s is distance zero from itself”
• Dj = Csj for all j s, distances of directly-connected neighbors
• Step A: (Find next closest node i)
• Find i N such that
• Di = min Dj for j N ,Add i to N,
• If N contains all the nodes, stop
• Step B: (update minimum costs)
• For each node j N
• Dj = min (Dj, Di+Cij)
• Go to Step A
Minimum distance from s to
j through node i in N
Dijkstra’s algorithm
• Find the shortest path from the source node(node 1) to all other
nodes
2 3
1 1
5 2
4
3 1 3 6
2
2 5
4
Execution of Dijkstra’s algorithm
2 2
1 3 1 1 3 1
6 6
5 2 5 2
3 3
1 4 1 4 2
2
3 3
2 2
4 5 4 5
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
Shortest path tree from node 1 to other
nodes
2 3
1 1
2
4
3 6
2
2 5
Consider the network in Figure below. Use the Dijkstra's algorithm to find
the set of shortest paths from node 1 to all other nodes.