Shortest Path Variants

You know Dijkstra and BFS. Now extend them with state-space search. Solve grid problems with obstacle elimination and multi-constraint shortest paths.

30 lessons
163 min
Codeforces: 1600-2100LeetCode: 1700-2100

Lessons

1. Introduction to Shortest Path Variants

Beyond basic BFS and Dijkstra

4m

2. What Shortest Path Variants Solve

Constraints that change the algorithm

4m

3. When to Use Each Algorithm

BFS vs 0-1 BFS vs Dijkstra

3m

4. State-Space BFS Pattern

The BFS state encoding

4m

5. Problem - Grid with Obstacles Elimination

LC 1293 - eliminate k obstacles

3m1 problems

6. Grid with Obstacles Elimination - Why Naive Fails

State = (row, col, remaining)

4m

7. Grid with Obstacles Elimination - Defining the DP

3D state: position + resource

4m

8. Grid with Obstacles Elimination - Transition

Empty = free, obstacle = costs 1

4m

9. Grid with Obstacles Elimination - Base Cases

1×1 grid, k ≥ path length

4m

10. Grid with Obstacles Elimination - Implementation

3D visited array or tuple set

5m1 problems

11. Grid with Obstacles Elimination - Time and Space

O(m·n·k) states visited once

3m

12. 0-1 BFS - The Deque Trick

Binary weight optimization

4m

13. Min Cost Valid Path - Why 0-1 BFS?

Choosing the right algorithm

4m

14. Ways to Arrive - Counting Shortest Paths

Counting optimal routes

4m

15. Problem - Min Cost Valid Path

LC 1368 - arrows and direction changes

3m1 problems

16. Min Cost Valid Path - Solution

0-1 BFS: free if arrow matches

4m1 problems

17. Problem - Ways to Arrive

LC 1976 - count shortest paths

3m1 problems

18. Ways to Arrive - Solution

dist[v] + ways[v] together

4m1 problems

19. Quiz: Pattern Recognition

Which algorithm fits?

3m1 problems

20. Quiz: Edge Cases

Negative edges, disconnected graphs

3m1 problems

21. Common Mistakes in Shortest Path

Wrong algorithm, missing copy

4m

22. Problem - Reachable Nodes In Subdivided Graph

LC 882 - subdivided edges

10m1 problems

23. Reachable Nodes In Subdivided Graph - Solution

The solution

10m

24. Problem - Shortest Path with Alternating Colors

LC 1129 - alternating edges

10m1 problems

25. Shortest Path with Alternating Colors - Solution

The solution

10m

26. Problem - Shortest Path Visiting All Nodes

LC 847 - visit all nodes

10m1 problems

27. Shortest Path Visiting All Nodes - Solution

The solution

10m

28. Problem - Minimum Weighted Subgraph

LC 2203 - weighted subgraph

10m1 problems

29. Minimum Weighted Subgraph - Solution

The solution

10m

30. Section Recap

State expansion to minimax paths

5m

Practice Problems

1.
Dijkstra?codeforces
2.
Paths and Treescodeforces
3.
Labyrinthcodeforces
4.
Buy a Ticketcodeforces
5.
Minimum Pathcodeforces
6.
7.
Three Statescodeforces

Ready to start learning?

Access all 30 lessons with interactive content and progress tracking.