70 likes | 215 Views
Shortest Path Algorithm. This is called “Dijkstra’s Algorithm”. …pronounced “Dirk-stra”. Problem:. Find the shortest route from A to F. Step 1 Label the start vertex S with a permanent label of 0.
E N D
Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”
Problem: Find the shortest route from A to F
Step 1 Label the start vertex S with a permanent label of 0 Step 2 Put a temporary label on each vertex that can be reached directly from the vertex that has just received a permanent label. The temporary label must be equal to the sum of the permanent label and the weight of the arc linking it directly to the vertex. If there is already a temporary label at the vertex, it is only replaced if the new sum is smaller.
Step 3 Select the minimum temporary label and make it permanent. Step 4 Repeat steps 2 and 3 until the destination vertex T receives its permanent label. Step 5 Trace back from T to S including an arc AB whenever the permanent label of B permanent label of A = the weight of AB, given that B already lies on the path.
Each vertex will have a box like the one below which has to be filled in:
Problem: Find the shortest route from A to F On the exam paper your diagram will look like this:
but 15 > 13 so ignore 15 B 3 7 D 5 13 8 7 13 16 – 13 = 3 so use DF Now trace back from F Third vertex is B Fifth vertex is D Sixth vertex is F Second vertex is C Fourth vertex is E First vertex is A 3 13 – 9 = 4 so use CD 7 Label 13 Label 12 Label 7 Label 0 Label 16 Label 4 4 – 0 = 4 so use AC A 1 0 F 6 16 17 16 5 9 Shortest Path is ACDF of length 16 4 Temporary Labels 5 C 2 4 E 4 12 9 4 13 12