Dijkstra Algorithm
Dijkstra Algorithm for Shortest Path · Also known as: Dijkstra's algorithm, shortest path algorithm
Dijkstra's Algorithm, introduced by Edsger W. Dijkstra in 1956, is one of the most fundamental algorithms in computer science for solving the single-source shortest path problem. It finds the shortest path from a starting vertex to all other vertices in a weighted graph with non-negative edge weights.
Read the full method
Sign in with a free account to read this section.
Method map
The neighbourhood of related methods — select a node to explore.
When to use it
Apply Dijkstra's algorithm when finding shortest paths in graphs with non-negative edge weights. It is ideal for navigation systems, network routing, and any graph problem requiring optimal paths. Use it for single-source shortest paths to all vertices. For graphs with negative weights, use Bellman-Ford instead. For bidirectional search or heuristic guidance, consider A* algorithm.
Strengths & limitations
- Simple to understand and implement with clear correctness guarantees
- Efficient with proper data structures: O((V+E)logV) with binary heap, O(V²) with array
- Optimal for non-negative weight graphs; proves optimality of computed paths
- Works on both directed and undirected graphs
- Foundation for numerous extensions and related algorithms
- Cannot handle graphs with negative edge weights
- Computes shortest paths to all vertices, not just one destination (though can terminate early)
- Less efficient than A* when heuristic information is available
- Requires all vertices to be discovered; inefficient for very sparse connectivity
Frequently asked
Why does Dijkstra's algorithm fail on negative weights?
The algorithm assumes that once a vertex is finalized, no shorter path can be found through unvisited vertices. With negative weights, a longer path might later improve when a negative edge is used, violating this assumption.
What data structure should be used for the priority queue?
Binary heaps provide O(logV) operations for both insertion and extraction, resulting in O((V+E)logV) total complexity. Fibonacci heaps achieve O(E+VlogV) but have large constant factors. Arrays work well for small graphs.
How can Dijkstra's algorithm find the path to one specific destination?
Terminate the algorithm as soon as the destination vertex is selected (its distance is finalized), avoiding unnecessary computation. Alternatively, reconstruct the path by maintaining parent pointers during execution.
Can Dijkstra's algorithm be used in undirected graphs?
Yes, undirected graphs can be represented as directed graphs with edges in both directions for each undirected edge, each with the same weight. The algorithm works identically on the bidirectional representation.
Sources
- Dijkstra, E. W. (1959). A note on two problems in connexion with graphs. Numerische Mathematik, 1(1), 269-271. DOI: 10.1007/BF01386390 ↗
- Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (3rd ed.). MIT Press. ISBN: 978-0-262-03384-8
How to cite this page
ScholarGate. (2026, June 3). Dijkstra Algorithm for Shortest Path. ScholarGate. https://scholargate.app/en/operations-research/dijkstra-algorithm
Which method?
Set this method beside its closest kin and read them side by side — the library lays the books on the table; the choice is yours.
- A-star Search AlgorithmOperations Research↔ compare
- Bellman-Ford AlgorithmOperations Research↔ compare
- Ford-Fulkerson AlgorithmOperations Research↔ compare