14 Shortest Path More Flashcards
Dijkstra’s algoirthm
Solves the single source shortest path problem in a weighted graph where all edge weights are non-negative.
Bellman-Ford Algorithm
Solves the single-source shortest path problem in a weighted graph with some negative edge weights as long as there are no negative weight cycles.
Can detect if there are any negative weight cycles in the graph.
Relaxation
Testing whether we can improve the shortest path to vertice v found so far by going through edge u.
If so, it lowers shortest path estimates and changes predecssors.
Bellman-Ford is designed for
Direct Graphs
If an undirect graph has no negative weight edges, Bellman-Ford will work, but . . .
Dijkstra’s algorithm will also work and will be faster.
Is it easier to find shortest path than in a directed acyclic graph that in a graph with cycles?
Yes.
Key idea that reduces time complexity is to consider vertices in topologically sorted order.
Longest path problem
Negate all weight and Find shortest path.
Negate Results
Complexity is O(V+E)
Both Dijkstra’s and Bellman ford algorithm are examples of
Dynamic Programming