DSA Lab
Dijkstra and Bellman-Ford
Dijkstra and Bellman-Ford find the cheapest path from a start node to every other node in a weighted graph. Dijkstra is fast but needs non-negative weights; Bellman-Ford is slower but handles negative weights and detects negative cycles.
Dijkstra and Bellman-Ford: how it works
In this tool: shortest paths, negative edges. Put in your own values and watch it change. Each operation runs one step at a time and says in plain words what happened, with its calculation worked out. The code is shown in Python, C, C++ or Java with the line that just ran marked, and an Understand it panel gives the idea, why it works, the cost of each operation, common mistakes and a short quiz.
Lessons that use it
- Shortest paths: Dijkstra and Floyd–Warshall (Algorithms)The cheapest route on a weighted graph: Dijkstra from one start vertex, Floyd–Warshall between every pair.
- Graphs with the STL (Competitive)Adjacency lists as vector<vector<int>>, BFS with queue, shortest paths on a grid, and Dijkstra with a priority_queue.
- Routing algorithms: link state and distance vector (Networks)How routers fill their tables: link-state routing with Dijkstra (OSPF), distance-vector routing with Bellman-Ford (RIP), and the count-to-infinity problem.