Advanced · Module 17 · Lesson 1 of 4
Dijkstra's algorithm
With non-negative edge weights, the unsettled vertex with the smallest tentative distance can never be improved, so Dijkstra's algorithm settles vertices one at a time in distance order, using a min-heap.
By the end you can
- Run Dijkstra's algorithm with a min-heap and lazy deletion of stale entries
- Explain why a popped vertex's distance is final when all weights are non-negative
- State its cost, recover paths, and adapt it to bottleneck problems
Builds on Breadth-first search, Top-k and merging streams.
01 · A question first
A navigation app finds the fastest route across a city of a million intersections in milliseconds. Breadth-first search counts streets, but streets take different times to drive. Which intersection should the search finish next, and why can that answer never be improved later?
Make a guess before you read on.
02 · The idea
Members only
Unlock the full lesson
This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.
What's inside
- Weighted shortest paths
- Settle the closest vertex next
- Why the popped distance is final
- Lazy deletion
- Cost
- Other path costs
- Mistakes to watch for
- Where it runs
03 · Practice
Asked in interviews
Something wrong with this lesson? Report a problem