Dijkstra & Bellman-Ford
We study shortest path algorithms for weighted graphs. Dijkstra's algorithm finds shortest paths from a single source in graphs with non-negative weights. Bellman-Ford handles negative weights and detects negative cycles.
Learning Objectives
Key Concepts
Dijkstra's Algorithm
Dijkstra's algorithm computes shortest paths from a source to all other vertices in a graph with non-negative edge weights. It greedily selects the unvisited vertex with smallest tentative distance.
- -
Only works with non-negative edge weights
- -
Greedy: always process the vertex with smallest current distance
- -
With binary heap:
- -
With simple array:
Bellman-Ford Algorithm
Bellman-Ford computes shortest paths from a source , handling negative edge weights. It relaxes all edges times. A final pass detects negative cycles.
- -
Works with negative weights (unlike Dijkstra)
- -
Detects negative cycles (if relaxation possible after rounds)
- -
Time: — slower than Dijkstra but more general
- -
iterations suffice because shortest paths have at most edges