The best shortest path algorithm

前端 未结 6 871
傲寒
傲寒 2020-12-01 04:02

What is the difference between the \"Floyd-Warshall algorithm\" and \"Dijkstra\'s Algorithm\", and which is the best for finding the shorte

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 04:20

    Floyd Warshall find the paths between all pairs of vertices, but Dijkstra only finds the path from one vertex to all others.

    Floyd Warshall is O(|V|3) and Dikstra is O(|E| + |V| log |V|) but you'll have to run it V times to find all pairs which gives a complexity of O(|E * V| + |V2| log |V|) I guess. This means it's possibly faster to use Dijsktra repeatedly than the FW algorithm, I would try both approaches and see which one is fastest in the actual case.

提交回复
热议问题