130 likes | 275 Views
Dijksta's algorithm. -to find the shortest path between 2 points. Notation. Final value (and last vertex visited). Order of labelling. Working values. Find the shortest path from A to G. 8. C. E. 5. 10. 6. 11. B. A. G. 7. 9. 4. 4. D. 12. F. 8. C. E. 5. 10. 6. 11. B.
E N D
Dijksta's algorithm -to find the shortest path between 2 points
Notation Final value (and last vertex visited) Order of labelling Working values
Find the shortest path from A to G. 8 C E 5 10 6 11 B A G 7 9 4 4 D 12 F
8 C E 5 10 6 11 B A G 7 9 4 4 D 12 F Label the start vetex with 0 and number it1 as it is the first vertex to be labelled. 1 0
The smallest working value is 7 at D, so label D with 7A and number it with 2, the second vertex to be labelled The working value for the path from A to C is 0+10=10 Vertices C and D can be reached directly from A, just labelled. 10A 8 C E 5 10 6 1 0 11 B A G 7 9 4 4 D 12 F 2 7A 7A The working value for the path from A to D is 0+7=7
The smallest working value is 10, at C, so label C with 10A and number it with 3, the third labelled vertex Vertices B and F can be reached directly from D, just labelled. 3 10A 10A 8 C The working value for the path from A to B is 7+9=16 E 5 10 6 1 0 11 16D B A G 7 9 4 4 The working value for the path from A to F is 7+12=19 D 12 F 2 7A 7A 19D
8 C E 5 10 6 11 B A G 7 9 4 4 D 12 F The smallest working value is 15, at B, so label B with 15C and number it with 4, the fourth labelled vertex Vertices B and E can be reached directly from D, just labelled. 3 10A The working value for the path from A to E is 10+8=18 10A 18C 4 15C 1 0 16D ,15C The working value for the path from A to B is 10+5=15 – need to update from 16. 2 7A 7A 19D
8 C E 5 10 6 11 B A G 7 9 4 4 D 12 F The smallest working value is 18, at E, so label E with 18C and number it with 5, the fifth labelled vertex Vertices F and G can be reached directly from D, just labelled. 3 10A 5 18C 10A 18C The working value for the path from A to G is 15+11=26 4 15C 1 0 16B, 15C 26B 2 7A The working value for the path from A to F is 15+4=19 – no change, do not need to update. 7A 19D 19DB
8 C E 5 10 6 11 B A G 7 9 4 4 D 12 F The smallest working value is 19, at F, so label F with 19DB and number it with 6, the sixth labelled vertex Only vertex G can be reached directly from E, just labelled. 3 10A 5 18C 10A 18C 4 15C 1 0 16B, 15C 26B , 24E The working value for the path from A to G is 18+6=24 – need to update from 26. 2 7A 6 19DB 7A 19DB
The smallest working value is 23, at G, so label G with 23F 8 C E 5 10 6 11 B A G 7 9 4 4 D 12 F and number it with 7, the seventh labelled vertex Only vertex G can be reached directly from F, just labelled. 3 10A 5 18C 10A 18C 4 15C 1 0 16B, 15C 7 23F 26B , 24E , 23F The working value for the path from A to G is 19+4=23 –update from 24. 2 7A 6 19DB 7A 19DB
There are no vertices that can be reached directly from G, as all vertices have been labelled. Backtrack to find the shortest path. Remember, the final values from A to each vertex are recorded in the top right hand corner of the box.
3 10A 5 18C 10A 18C 8 C E 5 10 6 4 15C 1 0 11 16B, 15C 7 23F B A G 26B , 24E , 23F 7 9 4 4 D 12 F 2 7A 6 19DB 7A 19DB
There are 2 shortest paths from A to G ADFG & ACBFG