Dijkstra's Algorithm

Priority queue implementation, lazy deletion, proof of correctness, and optimizations.

40 lessons
144 min

Lessons

1. Intro

Why BFS is not enough for weighted graphs

4m

2. Introducing Weights

Edge weights and their meanings

4m

3. The Greedy Strategy

Dijkstra's key insight

4m

4. Dijkstra's Algorithm - Setup

Initialization and data structures

5m

5. Dijkstra's Algorithm - The Loop

Processing nodes in order

4m

6. The Relaxation Step

Updating distances through edges

4m

7. Quiz: Dijkstra's Greedy Choice

Knowledge check

2m1 problems

8. Relaxation in Code

Complete code walkthrough

4m

9. Dijkstra - Implementation

Full pseudocode

4m

10. Complexity of Dijkstra

Time and space analysis

5m

11. Path Reconstruction in Dijkstra

Tracking the actual path

4m

12. Handling Large Weights

Overflow and precision concerns

3m

13. Quiz: Why Negative Edges Break Dijkstra

Knowledge check

2m1 problems

14. LeetCode 743 Network Delay Time - Problem Statement

Find minimum time for signal propagation

5m1 problems

15. LeetCode 743 Network Delay Time - Intuition

Understanding the problem

5m

16. LeetCode 743 Network Delay Time - Implementation

Code solution

2m

17. CSES 1671 Shortest Routes I - Problem Statement

Path reconstruction challenge

2m1 problems

18. LeetCode 1514 Path with Maximum Probability - Problem Statement

Adapting Dijkstra for products

4m1 problems

19. LeetCode 1514 Path with Maximum Probability - Modifying Dijkstra

Different metrics and objectives

3m

20. Quiz: Dijkstra Modifications

Knowledge check

2m1 problems

21. LeetCode 787 Cheapest Flights Within K Stops - Problem Statement

Dijkstra with constraints

5m1 problems

22. LeetCode 787 Cheapest Flights Within K Stops - State Definition

Expanded state space

3m

23. LeetCode 787 Cheapest Flights Within K Stops - Algorithm

Modified Dijkstra approach

5m

24. LeetCode 787 Cheapest Flights Within K Stops - Visited Set

Revisiting nodes in expanded state

3m

25. LeetCode 787 Cheapest Flights Within K Stops - Implementation

Code solution

5m1 problems

26. LeetCode 787 Cheapest Flights Within K Stops - Lessons

Key takeaways

4m

27. Quiz: Dijkstra with Constraints

Knowledge check

2m1 problems

28. LeetCode 1631 Path with Minimum Effort - Problem Statement

Minimax path problem

4m1 problems

29. LeetCode 1631 Path with Minimum Effort - Minimax Path

Maximum edge on path

4m

30. LeetCode 1631 Path with Minimum Effort - Algorithm

Modified Dijkstra for minimax

2m1 problems

31. LeetCode 1631 Path with Minimum Effort - Priority Queue

Heap structure for grid

3m

32. LeetCode 1631 Path with Minimum Effort - Implementation

Code solution

8m1 problems

33. LeetCode 1631 Path with Minimum Effort - Lessons

When to use minimax Dijkstra

3m

34. Quiz: Dijkstra on Grids

Knowledge check

2m1 problems

35. CSES 1195 Flight Discount - Problem Statement

One-time discount optimization

3m1 problems

36. CSES 1195 Flight Discount - State Definition

Tracking discount usage

4m

37. CSES 1195 Flight Discount - Algorithm

Two-state Dijkstra

3m

38. CSES 1195 Flight Discount - Implementation

Code solution

2m1 problems

39. CSES 1195 Flight Discount - Lessons

State expansion patterns

5m

40. Section Recap

Summary

2m

Practice Problems

1.
Network Delay TimeLeetCodemedium
2.
3.
4.
Dijkstra?Codeforceshard
5.
Edge DeletionCodeforceshard
6.
Jzzhu and CitiesCodeforceshard

Ready to start learning?

Access all 40 lessons with interactive content and progress tracking.