Dijkstra's algorithm: Difference between revisions

Line 1,196:
This implementation finds the single path from a source to all reachable vertices.
Building the graph from a set of edges takes O(E log V) for each pass.
Vertices are stored in a TreeSet (binary heap) instead of a PriorityQueue (a balanced binary heap) in order to get O(E log Vn) performance for removal of any element, not just the head.
Decreasing the distance of a vertex is accomplished by removing it from the heap and later re-inserting it.
<lang java>
41

edits