40 likes | 228 Views
Decision Maths 1. Shortest path algorithm Dijkstra’s Algorithm. A V Ali : www.2july-maths.co.uk. Dijkstra’s algorithm used to find the shortest path through a network. Set up 1 : Decide on a Start Node and End Node.
E N D
Decision Maths 1 Shortest path algorithm Dijkstra’s Algorithm A V Ali : www.2july-maths.co.uk
Dijkstra’s algorithm used to find the shortest path through a network. • Set up 1 : Decide on a Start Node and End Node. • Set up 2 : Add a recording box to each node in the network – use the following format to help keep track of each choice : • Box 1 : Route length to this node • Box 2 : Shortest Route • Box 3 : Node order • Step 1 : For first node label Box 1, 2 and 3 all 0. • Step 2 : Each node has Box 1 labeled as the shortest distance to this node from the start so far. • Step 3 : Go from each node labeled so far, and replace Box 1 value if a new shortest path from the start is found. • Step 4 : Repeat 3, for all nodes in the network. Label Box 2 when you have checked the shortest path has been found. Label Box 3 with the node order number through the path. Box 3 Box 2 Box 1
Find the shortest path from A to G 2 1 5 3 3 5 Step 1 : For first node label Box 1, 2 and 3 all 0. Step 2 : Each node has Box 1 labeled as the shortest distance to this node from the start so far. 3 6 6 8 7 6 17 0 0 19 17 18 0 Step 4 : Repeat 3, for all nodes in the network. Label Box 2 when you have checked the shortest path has been found. Label Box 3 with the node order number through the path. Step 3 : Go from each node labeled so far, and replace Box 1 value if a new shortest path from the start is found. Shortest route from A to G = 17 4 5 9 14 12 9 15 14