Untitled document (5)
Untitled document (5)
Since, we need to find the single source shortest path, we might initially
think of using Dijkstra’s algorithm. However, Dijkstra is not suitable when
the graph consists of negative edges. The reason is, it doesn’t revisit those
nodes which have already been marked as visited. If a shorter path exists
through a longer route with negative edges, Dijkstra’s algorithm will fail to
handle it.
Time Complexity:
● Best Case: O(E), when distance array after 1st and 2nd relaxation