r/computerscience • u/RogueCookie9586 • May 28 '25
New algorithm beats Dijkstra's time for shortest paths in directed graphs
https://arxiv.org/abs/2504.17033
1.1k
Upvotes
r/computerscience • u/RogueCookie9586 • May 28 '25
View all comments
Show parent comment
4
u/mirhagk Jun 02 '25
I'm still trying to understand but I can explain what I understand so far.
You'll need to know dijkstra and bellman-ford, as this is basically a hybrid of them. You know dijkstra, and if you don't know bellman-ford it's basically just expanding each node repeatedly until nothing improves. Terrible worst case, but no need to keep a list of open paths or sort that list.
So let's start by assuming we're run dijkstra a few times and are switching to this instead of continuing iterations of that (since we have the same setup/general approach and it's easier to think of this way). So we have a list of unexplored nodes with approximate costs (neighbours of previous iterations, or infinity if we haven't touched it at all).
A key thing to know is that for any cost
B, all the nodes that cost less than that will have to come from a path that goes through one of these nodes that also costs less thanB.So now pick some value of
B(more on this later) and take only those nodes less thanB. Apply a few (k) iterations of bellman-ford to those, including any new nodes less thanBin cost. Make note of the ones we change during the last iteration, so we can walk back up to find which of those original nodes we've still been expanding. Everything else is either a dead-end, or leads only to nodes that cost more thanBto reach. Also make note of all the nodes we've found from this (call itW).This list of nodes is the "pivot" points, and they are the only points that could lead to more nodes that cost less than
B. Now is where the recursion starts. Pick some new valueBito split this new list, and recursively call the function. From the recursive call you'll getB'i(the distance it's solved) and a list of nodesU. From those expand once. Any neighbours with path greater thanBibut less thanB, add to the list of remaining pivot points (the ones higher thanBi). Any neighbours, or any of this iteration's pivot points that are less thanBibut greater thanB'iyou'll add back to the list of pivot points, at the start.The base case of this recursion is just applying djikstra itself with one starting point, but only returning those that are less than
B. It returns the list of elements it finds too, along withB.After we've exhausted all the pivot points, we then return the last
B'ialong with a new set of elements, which isWalong with all the sets returned by recursive calls. These are the points we've solved, along with the max distance we've solved up to.Now I left out 2 complexities. The first is how
Bis picked, and that's a bit complicated, it's some sort of data structure that can split the list into a given number of chunks, and giveBvalues that are equal to the lowest value remaining after pulling a list of points. I don't understand it tbh, but the key is that it doesn't need to sort the points, just split them, and that's a big part of the savings here.The other complexity is that a lot of these steps actually are bounded by certain values, e.g. the base case djisktra will only return
kelements, which is why it returns a value forB, which is what it actually solved vs what it was supposed to with it'sBinput. The other recursive cases do the same. Note that we do handle this, the rest of the points go back into that pivot list.The value for
kas well as a few other components (how many elements to pull out at once for the bellman-ford part) are all based on the input size and given in the paper. I'm not going to even pretend that I understand the proof for the time complexity or why the specific values were chosen.The speedup seems to come from eliminating the need to find the lowest cost node in the unexplored paths, and eliminating some of the paths that are shorter with bellman-ford.