1

For example, if I ran Dijkstra's algorithm for each vertex, would that produce the all pair shortest path for the entire graph like when running Floyd-Warshall?

I am leaning towards this being true with the caveat being that running the single source shortest path algorithm for each vertex is less efficient since it wouldn't utilize dynamic programming to avoid redundant computations.

1 Answers1

0

Yes, you can produce the all pairs shortest paths. And it is faster compared to Floyd Warshall algorithm: For a graph consisting of n vertices and m edges, the complexity of Dijkstra for a single source is O(mlogn) if you use a binary heap. Therefore, for all pairs shortest paths the complexity is O(mnlogn). Floyd Warshall algorithm has complexity O(n^3).

ckc
  • 345
  • 4
  • 12
  • Thanks for the insight. So is it valid to say that if you have a graph with only positive weight edges, to find the all pairs shortest paths, it would be more efficient to complete n iterations of Djikstra's rather than running Floyd-Warshall once? If so, does that mean Floyd-Warshall is really only useful for finding the all pairs shortest path when the graph has negative weighted edges or negative cycles? – Matt Boraske Mar 23 '23 at 22:36
  • @MattBoraske yes Djikstra's algorithm is more efficient, i.e. it has lower computational complexity, as long as it is applied with a binary heap. Indeed it cannot be used to graphs with negatively weighted edges, whereas Floyd-Warshall algorithm can be used. None of these algorithms can be used to graphs with negative cycles though. – ckc Mar 24 '23 at 08:53