Dijkstrasalgorithm 2
Dijkstrasalgorithm 2
1205
43 LGA
802
17
1205
337
7 43 LGA
138 10 17
337
HNL 2555 99 7
LAX 1233
HNL 2555 138 10
99
DFW 1120 1233
LAX DFW 1120
MIA
MIA
Shortest Paths 3 Shortest Paths 4
43 LGA
1
Shortest Path 5/15/2002 11:40 AM
5 3 9 11 5 3 9 8
2 5 2 5
E F E F
Shortest Paths 7 Shortest Paths 8
Analysis Extension
Graph operations Using the template Algorithm DijkstraShortestPathsTree(G, s)
Method incidentEdges is called once for each vertex method pattern, we
Label operations can extend Dijkstra’s …
We set/get the distance and locator labels of vertex z O(deg(z)) times algorithm to return a
tree of shortest paths for all v ∈ G.vertices()
Setting/getting a label takes O(1) time …
from the start vertex
Priority queue operations setParent(v, ∅)
to all other vertices
Each vertex is inserted once into and removed once from the priority …
queue, where each insertion or removal takes O(log n) time We store with each
The key of a vertex in the priority queue is modified at most deg(w) vertex a third label: for all e ∈ G.incidentEdges(u)
times, where each key change takes O(log n) time parent edge in the { relax edge e }
shortest path tree z ← G.opposite(u,e)
Dijkstra’s algorithm runs in O((n + m) log n) time provided the
In the edge relaxation r ← getDistance(u) + weight(e)
graph is represented by the adjacency list structure
step, we update the if r < getDistance(z)
Recall that Σv deg(v) = 2m parent label setDistance(z,r)
The running time can also be expressed as O(m log n) since the setParent(z,e)
graph is connected Q.replaceKey(getLocator(z),r)
2
Shortest Path 5/15/2002 11:40 AM
3
Shortest Path 5/15/2002 11:40 AM