The best shortest path algorithm

前端 未结 6 869
傲寒
傲寒 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

    Dijkstra's is mainly for single pair shortest path finding i.e. from one node to all other nodes, where as Floyd-Warshall is for all-pair shortest path i.e. shortest path between all pair of vertices. The Floyd-Warshall algorithm has a worst case performance of O(|V|3), where as Dijkstra's has a worse case performance of O(|E| + |V|log |V|) Also Dijkstra's cannot be used for negative weights ( we use Bellmann Ford for the same ). but for Floyd-Warshall we can use negative weights but no negative cycles

提交回复
热议问题