We all know Dijkstra and so on. But is there a way to extend this to get the N best shortest paths between 2 nodes? ...and still with "acceptable" complexity.

Thanks, Arnaud

  • 5
    $\begingroup$ The literature about this uses a different variable: search for "k-shortest path" and you should turn up lots of material. $\endgroup$ Feb 4, 2011 at 15:41
  • $\begingroup$ ...well, I would be glad to accept the comment as correct answer ...but it is only a comment $\endgroup$
    – dagnelies
    Feb 4, 2011 at 16:07

1 Answer 1


From Wikipedia:

The functionality of Dijkstra's original algorithm can be extended with a variety of modifications. For example, sometimes it is desirable to present solutions which are less than mathematically optimal. To obtain a ranked list of less-than-optimal solutions, the optimal solution is first calculated. A single edge appearing in the optimal solution is removed from the graph, and the optimum solution to this new graph is calculated. Each edge of the original solution is suppressed in turn and a new shortest-path calculated. The secondary solutions are then ranked and presented after the first optimal solution.

However, this probably doesn't cover "acceptable" complexity. Also, it doesn't necessarily find all near-optimal paths. (E.g. consider the case where there exists a very small loop from one of the cities on the optimal path to itself; the optimal path plus this loop might be the second-most-optimal path, but wouldn't be picked up by the above.)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .