Bellman-Ford Algorithm

Dijkstra breaks with negative edges. Bellman-Ford handles them and detects negative cycles. You'll learn when to use each algorithm.

48 lessons
138 min

Lessons

1. Intro

(Why you need it)

3m

2. When Dijkstra Fails

(Negative edge problem)

3m

3. The Relaxation Operation

(Core building block)

3m

4. Bellman-Ford Strategy

(Relax all edges repeatedly)

3m

5. Why $n-1$ Iterations

(Maximum path length)

3m

6. Basic Bellman-Ford Implementation

(The algorithm)

3m

7. Time Complexity Analysis

(Why it's slower)

3m

8. Quiz: Relaxation and Iterations

Knowledge check

2m1 problems

9. Detecting Negative Cycles

(The $n$-th iteration)

3m

10. Finding Affected Nodes

(Reachability from cycle)

3m

11. CSES 1673 High Score - Problem Statement

(CSES 1673)

3m1 problems

12. CSES 1673 High Score - Negating Weights

(Maximum becomes minimum)

3m

13. CSES 1673 High Score - Detecting Positive Cycles

(In the original graph)

3m

14. CSES 1673 High Score - Two-Way Reachability

(Cycle must matter)

3m

15. CSES 1673 High Score - Algorithm

(Step-by-step approach)

3m

16. CSES 1673 High Score - Implementation

(Pseudocode walkthrough)

3m1 problems

17. CSES 1673 High Score - Walkthrough

(Trace execution)

3m

18. CSES 1673 High Score - Lessons

(summary)

3m

19. Quiz: Negative Cycle Reachability

Knowledge check

2m1 problems

20. CSES 1197 Cycle Finding - Problem Statement

(CSES 1197)

3m1 problems

21. CSES 1197 Cycle Finding - Parent Tracking

(Reconstructing the cycle)

3m

22. CSES 1197 Cycle Finding - Finding Cycle Start

(Inside the cycle)

3m

23. CSES 1197 Cycle Finding - Algorithm

(Detection and extraction)

3m

24. CSES 1197 Cycle Finding - Implementation

(Pseudocode walkthrough)

3m1 problems

25. CSES 1197 Cycle Finding - Walkthrough

(Trace execution)

3m

26. CSES 1197 Cycle Finding - Lessons

(summary)

3m

27. Quiz: Cycle Reconstruction

Knowledge check

2m1 problems

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

(LeetCode 787)

3m1 problems

29. LeetCode 787 Cheapest Flights Within K Stops - Layer-by-Layer Relaxation

(Limiting path length)

3m

30. LeetCode 787 Cheapest Flights Within K Stops - Temporal Separation

(Why two arrays matter)

3m

31. LeetCode 787 Cheapest Flights Within K Stops - Algorithm

(Modified Bellman-Ford)

3m

32. LeetCode 787 Cheapest Flights Within K Stops - Implementation

(Pseudocode walkthrough)

3m1 problems

33. LeetCode 787 Cheapest Flights Within K Stops - Walkthrough

(Trace execution)

3m

34. LeetCode 787 Cheapest Flights Within K Stops - Lessons

(summary)

3m

35. Quiz: Bounded Relaxation

Knowledge check

2m1 problems

36. SPFA Improvement

(Queue-based relaxation)

3m

37. SPFA Implementation

(Queue-based approach)

3m

38. SPFA Cycle Detection

(Counting relaxations)

3m

39. When to Use Bellman-Ford

(Dijkstra vs Bellman-Ford)

3m

40. Application: Currency Arbitrage

(Detecting profit cycles)

3m

41. Quiz: Algorithm Selection

Knowledge check

2m1 problems

42. Application: Network Routing

(Handling link costs)

3m

43. Edge Cases and Mistakes

(What can go wrong)

3m

44. Comparison Summary

(Algorithm characteristics)

3m

45. Common Mistakes

(What to avoid)

3m

46. Quiz: SPFA Worst Case

Knowledge check

2m1 problems

47. Practice Strategy

(How to internalize this)

3m

48. Section Recap

(What you learned)

3m

Practice Problems

3.
High ScoreCSEShard
4.
Cycle FindingCSESmedium
5.
The Two RoutesCodeforcesmedium
6.
President and RoadsCodeforceshard

Ready to start learning?

Access all 48 lessons with interactive content and progress tracking.