Experiment № 109 · The story
Back With More
Why I picked it
Dijkstra already turned up in this collection, hiding inside A*, and I'd always filed Bellman–Ford as the slower cousin you use when someone hands you negative edges. Then I met the currency version, where taking the logarithm of each exchange rate turns a chain of multiplications into a sum of lengths, and a loop of trades that pays becomes a road that's shorter than staying put. That one change of units turns the slow cousin into the only tool for the job, and I wanted to watch it happen.
What I enjoy about it
How dumb each step is. It doesn't search, prioritise or plan. It walks the whole list of trades and asks the same question of each one: would going through here be better? Then it does it all again. What I like most is the extra lap at the end. The algorithm knows that any honest route visits each currency at most once, so it's finished after n − 1 passes. If anything still improves on pass n, the only explanation is a loop that keeps paying, and following the via pointers back lands you on it. Turn the mispricing up and you can watch the numbers keep climbing, pass after pass, because nothing can stop them.
Something you might take away
Knowing when you should be finished is as useful as knowing how to finish. Bellman–Ford's last pass isn't more work towards the answer; it's a test of whether the world is the kind of place where an answer exists. And the log trick is worth keeping in your pocket: when things compound by multiplying, take logs and they add up like distances, and every tool built for distances works on them. Real arbitrage is mostly fees and latency, by the way. Push the fee slider up a little and most of the free money disappears.