Comparing Single Source Shortest Path and All Pairs Shortest Path Algorithms
- Get link
- X
- Other Apps
Single Source Shortest Path Algorithms
BFS | Dijkstra's Algorithm | Bellman Ford Algorithm | |
Time Complexity | O(V^2) | O(V^2) | O(E.V) |
Space Complexity | O(E) | O(V) | O(V) |
Limitation | Does not work for weighted graphs in general. If all weight is same in weighted graph or can be made same, then it will work for weighted graph as well | Works for weighted as well as unweighted graph. Does not work is there is a negative cycle in the graph. Not able to detect negative cycle. | No limitation for working. Works for all kinds of graph as well as able to detect negative cycle in the graph. Only disadvantage is it's runtime complexity is highest here as compared to BFS, Dijkstra and Floyd Warshall |
Working for Unweighted Graph | use this as it is easy to implement | Avoid it as we have to implement a min heap too in this case which will slow this down | Avoid it as Time Complexity is not good |
Working for Weighted Graph (no negative cycle) | Not supported | can be used | Avoid it as Time Complexity is not good |
Working for Weighted Graph ( with negative cycle) | Not supported | Not supported | Only choice |
All Pairs Shortest Path Algorithms
BFS | Dijkstra's Algorithm | Bellman Ford Algorithm | Floyd Warshall Algorithm | |
Time Complexity | O(V^3) | O(V^3) | O(E.V^2) | O(V^3) |
Space Complexity | O(E.V) | O(E.V) | O(V^2) | O(V^2) |
Limitation | Does not work for weighted graphs in general. If all weight is same in weighted graph or can be made same, then it will work for weighted graph as well | Works for weighted as well as unweighted graph. Does not work is there is a negative cycle in the graph. Not able to detect negative cycle. | No limitation for working. Works for all kinds of graph as well as able to detect negative cycle in the graph. Only disadvantage is it's runtime complexity is highest here as compared to BFS, Dijkstra and Floyd Warshall | Works for weighted as well as unweighted graph. Does not work is there is a negative cycle in the graph. Not able to detect negative cycle. |
Working for Unweighted Graph | use this as it is easy to implement | Avoid it as we have to implement a min heap too in this case which will slow this down | Avoid it as Time Complexity is not good | can be used |
Working for Weighted Graph (no negative cycle) | Not supported | can be used | Avoid it as Time Complexity is not good | Preferable Choice as easier to implement |
Working for Weighted Graph ( with negative cycle) | Not supported | Not supported | Only choice | Not supported |
All Pairs Shortest Path
APSP
Bellman Ford
BFS
Dijkstra
Floyd Warshall Algorithm
graphs
Shortest Path
Single Source Shortest Path
SSSP
- Get link
- X
- Other Apps
Comments
Post a Comment