Every time a navigation app finds the fastest route, it runs a shortest-path algorithm — most likely Dijkstra's. And at the heart of Dijkstra's algorithm sits a single operation repeated thousands of times: decrease-key, the act of updating a node's tentative distance when a shorter path is found.
With a binary heap — the default priority queue in most textbooks — decrease-key costs . That gives Dijkstra an overall complexity of , where is edges and is vertices. Fine for small graphs, but not optimal.
In 1987, Michael Fredman and Robert Tarjan invented the Fibonacci heap, a priority queue that reduces decrease-key to amortized . The result: Dijkstra runs in — a genuine improvement on dense graphs, and the theoretical optimum for comparison-based shortest paths.
The trick is pure laziness: when you decrease a key, just cut that node out of its tree and throw it on a loose pile. Don't reorganize anything until you absolutely must. It sounds reckless. It works.
Comments
Loading comments...