Modul Shortest Path
Modul Shortest Path
SSSP Algorithms
• Breadth-First Search
• Dijkstra
• Bellman-Ford
• We want to find all vertices which we can get to from a starting point, call it A
The algorithm:
• We visit all the closest vertices
first
• Then once all the closest vertices are visited, branch further out
• It is similar with level-order traversal
• We’re going to use a queue
Algorithm:
• Start at a vertex, call it current
• If there is an unvisited neighbor, mark it, and insert it into the queue
• If there is not:
• If the queue is empty, we are done, otherwise:
• Remove a
vertex
from the
queue and
set current
to that
vertex, and
repeat the
process
Bellman-Ford Algorithm
Dijkstra doesn’t work for Graphs with negative weights, Bellman-Ford works for such graphs.
Bellman-Ford is also simpler than Dijkstra and suites well for distributed systems. But time
complexity of Bellman-Ford is O(VE), which is more than Dijkstra. Bellman is a dynamic programming
algorithm. While dijkstra is greedy.