Network algorithms 2. Shortest paths Flashcards
1
Q
What is Dijkstra’s algorithm?
A
Dijkstra’s algorithm finds the shortest path between two nodes in an undirected algorithm.
2
Q
How is the working for Dijkstra’s algorithm shown?
A
The working is shown in boxes drawn at each node which will contain the following information:
Top left box - Order of permanent labelling
Top right box - Permanent label (shortest distance)
Bottom box - Temporary labels (working values)
3
Q
How do you carry out Dijkstra’s algorithm?
A
- Label the start vertex with permanent label 0 and order label 1
- Assign temporary labels to all the vertices that can be reached directly from the start
- Select the vertex with the smallest temporary label and make its label permanent. Add the correct order label.
- Put temporary labels on each vertex that can be reached directly from the vertex you have just made permanent. The temporary label must be equal to the sum of the permanent label and the direct distance from it. If there is an existing temporary label at a vertex, it should be replaced only if the new sum is smaller.
- Select the vertex with the smallest temporary label and make its label permanent. Add the correct order label.
- Repeat until the finishing vertex has a permanent label.
- To find the shortest paths(s), trace back from the end vertex to the start vertex. Write the route forwards and state the length.
4
Q
What complexity does Dijkstra’s algorithm have?
A
Dijkstra’s algorithm has complexity O(n^2), where n is the number of nodes.