Ethan Stanley Dijkstra-Alg. Slides
Ethan Stanley Dijkstra-Alg. Slides
Weighted graph: the edges of the graph have weights (as in the
length of a street)
Step 1: Pick a start node, and mark all other nodes as unvisited (Dijkstra’s algorithm will find the shortest
path from this node to every other node in this graph)
Step 2: Look at all the nodes adjacent to the node you are on and examine their distances (adjacent nodes
are connected to your start node with one edge)
A. Distance to node (1): 2 B. Distance to node (2): 1
Step 3:Visit the closest node, and mark it as visited (it will not be checked again)
A. Visit node 2
Step 4:Visit the next closest node that has not yet been visited (only look at nodes adjacent to visited
nodes)
A. Distance to node (1): 2 B. Distance to node (5): 16 C. Visit Node 1
Step 5:Visit the next closest node that has not yet been visited (only look at nodes adjacent to visited
nodes)
A. Distance to node (3): 13 B. Distance to node (4): 5 C. Distance to node (5): 16 D. Visit node (4)
Step 6: Visit the next closest node that has not yet been visited (only look at nodes adjacent to visited
nodes)
A. Distance to node (5): 9 B. Distance to node (6): 10 C. Distance to node (3): 13 D.Visit node (5)
NODE
0 1 2 3 4 5 6
#
DISTANCE 0 2 1 13 5 9 10
NODES
USED 0 0,1 0,2 0 0,1,4,6,3 0,1,4,5 0,1,4,6
APPLYING DIJKSTRA’S ALGORITHM TO CAMPUS
http://www.geeksforgeeks.org/greedy-algorithms-set-6-dijkstras-shortest-path-algorithm/
• Graph Characteristics: 4
75
50
5
17
0-7 : 50 52
+
7-6 : 40
6
24
+ 2
.
29
6-5 : 17 +
8
40
5-4 : 45 37
29
152 33 7
50
34
http://www.geeksforgeeks.org/greedy-algorithms-set-6-dijkstras-shortest-path-algorithm/
The End