Finding the cheapest route through a network is one of the oldest questions in computing. Map apps do it millions of times a second, and the famous fast answer is Dijkstra's algorithm â greedily expand outward, always grabbing the nearest unvisited node.
But Dijkstra rests on one quiet assumption: every edge costs something positive. The moment a road can give you value back â a currency trade that pays off, a discount, a refund â that greedy logic falls apart. A node Dijkstra "finalized" early can suddenly become cheaper through a negative detour it never considered.
The Bellman-Ford algorithm (Richard Bellman and Lester Ford, 1958) handles exactly this case. It is slower, but it is honest: it works with negative edge weights, and it can tell you when the question has no answer at all â when a negative cycle lets you loop forever and keep getting cheaper.
Comments
Loading comments...