# Comparison of Dijkstra’s and Floyd–Warshall algorithms

**Main Purposes: **

- Dijkstra’s Algorithm is one example of a single-source shortest or SSSP algorithm, i.e., given a source vertex it finds shortest path from source to all other vertices.
- Floyd Warshall Algorithm is an example of all-pairs shortest path algorithm, meaning it computes the shortest path between all pair of nodes.

**Time Complexities : **

- Time Complexity of Dijkstra’s Algorithm: O(E log V)
- Time Complexity of Floyd Warshall: O(V
^{3})

**Other Points:**

- We can use Dijskstra’s shortest path algorithm for finding all pair shortest paths by running it for every vertex. But time complexity of this would be O(VE Log V) which can go (V
^{3}Log V) in worst case. - Another important differentiating factor between the algorithms is their working towards distributed systems. Unlike Dijkstra’s algorithm, Floyd Warshall can be implemented in a distributed system, making it suitable for data structures such as Graph of Graphs (Used in Maps).
- Lastly Floyd Warshall works for negative edge but no negative cycle, whereas Dijkstra’s algorithm don’t work for negative edges.

This article is contributed by **Vineet Joshi**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

## Recommended Posts:

- Comparison between Adjacency List and Adjacency Matrix representation of Graph
- What are the differences between Bellman Ford's and Dijkstra's algorithms?
- Minimum nodes to be colored in a Graph such that every node has a colored neighbour
- Finding shortest path between any two nodes using Floyd Warshall Algorithm
- Proof that Clique Decision problem is NP-Complete | Set 2
- Count of all cycles without any inner cycle in a given Graph
- Isomorphism in N-ary Trees
- Sum of minimum element at each depth of a given non cyclic graph
- Minimum Manhattan distance covered by visiting every coordinates from a source to a final vertex
- Minimum clicks to convert string X to Y
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Proof that Independent Set in Graph theory is NP Complete
- Length of longest connected 1’s in a Binary Grid
- Check if it is possible to reach to the index with value K when start index is given