Difference between revisions of "Shortest Path"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 14: Line 14:
 
'''Step 6''' Use the permanent labels to trace back through the network to find the shortest path.
 
'''Step 6''' Use the permanent labels to trace back through the network to find the shortest path.
  
'''Step 7''' The shortest path is found by tracing back in such a way that an edge is only included if
+
'''Step 7''' The shortest path is found by tracing back in such a way that an edge is only included if its distance equals the change in label values.
              its distance equals the change in label values.
 
  
  

Revision as of 12:26, 23 May 2017

The shortest path is usually found by Dijkstra's algorithm. The algorithm functions as follows:

Step 1 Give the permanent label 0 to the starting vertex.

Step 2 Give temporary labels to each vertex that is connected directly to the starting vertex.

Step 3 Find the vertex with the smallest temporary label, number it and make it permanent.

Step 4 Give temporary labels to each vertex that is connected directly to the previous vertex. Then find the vertex with the smallest temporary label, number it and make it permanent.

Step 5 Repeat Step 4 until you have given a permanent label to the finishing vertex.

Step 6 Use the permanent labels to trace back through the network to find the shortest path.

Step 7 The shortest path is found by tracing back in such a way that an edge is only included if its distance equals the change in label values.


Example

This is the starting graph and values:

Shortest path eg start.gif

The stages to identify the shortest path:

Shortest path example.gif

Further Example

Dijkstra.png