Understanding Weighted Graphs
A Weighted Graph is a graph in which a number (the weight) is assigned to each edge. Such weights might represent costs, lengths or capacities, depending on the problem at hand. They are heavily used in GPS navigation systems, network routing, and resource allocation problems.
Dijkstra vs. Bellman-Ford
- Dijkstra: Faster (O(E + V log V)), but fails with negative edge weights.
- Bellman-Ford: Slower (O(VE)), but handles negative weights and detects negative cycles.