Running Time
An upper bound of the running time of Dijkstra's algorithm on a graph with edges and vertices can be expressed as a function of and using big-O notation.
For any implementation of vertex set the running time is in, where and are times needed to perform decrease key and extract minimum operations in set, respectively.
The simplest implementation of the Dijkstra's algorithm stores vertices of set in an ordinary linked list or array, and extract minimum from is simply a linear search through all vertices in . In this case, the running time is .
For sparse graphs, that is, graphs with far fewer than edges, Dijkstra's algorithm can be implemented more efficiently by storing the graph in the form of adjacency lists and using a binary heap, pairing heap, or Fibonacci heap as a priority queue to implement extracting minimum efficiently. With a binary heap, the algorithm requires time (which is dominated by, assuming the graph is connected). To avoid O(|V|) look-up in decrease-key step on a vanilla binary heap, it is necessary to maintain a supplementary index mapping each vertex to the heap's index (and keep it up to date as priority queue changes), making it take only time instead. The Fibonacci heap improves this to .
Note that for directed acyclic graphs, it is possible to find shortest paths from a given starting vertex in linear time, by processing the vertices in a topological order, and calculating the path length for each vertex to be the minimum length obtained via any of its incoming edges.
Read more about this topic: Dijkstra's Algorithm
Famous quotes containing the words running and/or time:
“Swan/Mary Rutledge: Oh no, no. Im not running away. I came here to get something, and Im going to get it.
Col. Cobb: Yes, but San Francisco is no place for a woman.
Swan: Why not? Im not afraid. I like the fog. I like this new world. I like the noise of something happening.... Im tired of dreaming, Colonel Cobb. Im staying. Im staying and holding out my hands for goldbright, yellow gold.”
—Ben Hecht (18931964)
“O Time and Change!with hair as gray
As was my sires that winter day,
How strange it seems, with so much gone
Of life and love, to still live on!
Ah, brother! only I and thou
Are left of all that circle now,
The dear home faces whereupon
That fitful firelight paled and shone.”
—John Greenleaf Whittier (18071892)