Dijkstra’s Shortest-Path Algorithm
With nonnegative edge weights, process the unsettled vertex with the smallest tentative distance.
Core Intuition & How It Works
Dijkstra’s algorithm computes single-source shortest paths in graphs with non-negative edge weights by repeatedly settling the closest unvisited vertex via a min-heap and relaxing its outgoing edges.
In the Byte Sized Algorithms interactive classroom, you can step forward and backward through this algorithm with your keyboard while watching the visual diagram, memory state, and highlighted pseudocode update together.
Time & Space Complexity
| Metric | Complexity |
|---|---|
| Time Complexity | O((V + E) log V) |
| Space Complexity | O(V + E) |
| Topic Chapter | Chapter 12: Shortest Paths & Spanning Trees |
| Difficulty Level | Advanced |
Key Pattern to Recognize
Skip stale priority-queue entries whose popped distance exceeds dist[u], guaranteeing each vertex’s edges are relaxed once.
Common Pitfalls & Edge Cases
Running Dijkstra on graphs with negative edge weights, where a settled vertex’s distance can later be invalidated.
Real-World & Technical Interview Applications
GPS navigation, OSPF network routing, flight/transit planners, and A* pathfinding foundation.