Lesson 65 of 86AdvancedPro Interactive Lesson

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

MetricComplexity
Time ComplexityO((V + E) log V)
Space ComplexityO(V + E)
Topic ChapterChapter 12: Shortest Paths & Spanning Trees
Difficulty LevelAdvanced

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.

Unlock the full course

All 86 lessons across 15 chapters

View pricing

Delete account

This permanently deletes your account and ends any Pro access.