It seems that for sparse graphs with weighted edges Dijkstra’s algorithm it more useful, because it runs faster than Floyd-Warshall one. For other graphs it is better to use Floyd-Warshall to compute the shortest path., because Dijkstra’s one would fail here.
It seems that for sparse graphs with weighted edges Dijkstra’s algorithm it more useful, because it runs faster than Floyd-Warshall one. For other graphs it is better to use Floyd-Warshall to compute the shortest path., because Dijkstra’s one would fail here.
Dijkstra’s algorithm finds the shortest path between a single pair of nodes, while Floyd-Warshall finds the shortest paths between all pairs of nodes. Of course, you can use Dijkstra’s algorithm to find the shortest paths between all pairs of nodes, and if this is what you need to do I support the answer of Tadeusz Ostrowski above. One of my research students was working with sparse graphs and found that Dijkstra’s algorithm is faster.
If you just want to find a shortest path between two specified vetices, then Dijkstra is more useful. Otherwise depending on the contexts, Floyd Warshall could be more useful.
Dijkstra's algorithms computes the shortest path from a given source node in time O(n^2) in the basic implementation, and time O(m log m) if you use priority queues, where n = |V| and m = |E| are the sizes of the vertex (V) and edges (E) set respectively. In the case of spare graphs is much better the priority queue variant (as m < n^2). It uses O(n) extra memory.
On the other hand, Floyd-Warshall computes the shortest path between every pair of nodes in time O(n^3). It uses O(n^2) extra memory.
If you need to compute a the shortest path between a given pair of nodes, use Dijstra's. In practice, Floyd-Warshall is useful for small graphs as it uses a lot of memory for the computation.
Best regards, and sorry for the delay in the answer.
Both Floyd’s and Dijkstra’s algorithm may be used for finding the shortest path between vertices. The biggest difference is that Floyd’s algorithm finds the shortest path between all vertices and Dijkstra’s algorithm finds the shortest path between a single vertex and all other vertices. The space overhead for Dijkstra’s algorithm is considerably more than that for Floyd’s algorithm. If you run Dijkstra’s algorithm n times, on n different vertices, you will have a theoretical time complexity of O(n* n2)=O(n3). In other words, if you use Dijkstra’s algorithm to find a path from every vertex to every other vertex you will have the same efficiency and result as using Floyd’s algorithm.In addition, Floyd’s algorithm is much easier to implement.