Dijkstra'S Algorithm
A graph algorithm to find the shortest path from a source to all other vertices.
Time Complexity
O(V + E log V)
?Space Complexity
O(V)
?In-Place
No
NoStability
Yes
YesDifficulty
Extreme
★★★★★Description
Dijkstra's algorithm solves the single-source shortest path problem for graphs with non-negative edge weights.
It maintains a set of vertices with known shortest distances and iteratively expands this set using a greedy approach.
Steps:
- Initialize distances and priority queue
- Pick the vertex with the smallest tentative distance
- Update distances to its neighbors
- Repeat until all vertices are processed
Using a priority queue (e.g., a min-heap) makes the algorithm more efficient on sparse graphs.