# 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.

## Recommended Posts:

- Print the path between any two nodes of a tree | DFS
- Number of shortest paths to reach every cell from bottom-left cell in the grid
- Product of minimum edge weight between all pairs of a Tree
- Minimum Possible sum of digits in a positive multiple of N
- Find the maximum cost path from the bottom-left corner to the top-right corner
- Implementing Generic Graph in Java
- Find the winner of the match | Multiple Queries
- Lexicographically Smallest Topological Ordering
- Introduction to Data Structures | 10 most commonly used Data Structures
- Find the number of paths of length K in a directed graph
- Build original array from the given sub-sequences
- Find K vertices in the graph which are connected to at least one of remaining vertices
- Pair with a given sum in BST | Set 2
- Find two disjoint good sets of vertices in a given graph