1. Ray Anthony Saavedra
ArrizPaul San Juan
IT2A
THE PROBLEM: SINGLE-SOURCE SHORTEST PATH (SSSP)
In graph theory, the shortest path problem is the problem of finding a path between
two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is
minimized. An example is finding the quickest way to get from one location to another on a road
map; in this case, the vertices represent locations and the edges represent segments of road and
are weighted by the time needed to travel that segment. The problem is also sometimes called the
single-pair shortest path problem. It is used to find the shortest paths from a source vertex v to all
other vertices in the graph.
THE PRACTICAL APPLICATIONS:
1.) Finding the shortest path from your house to your school
2.) If you want to deliver something, you can use it to find the shortest path to your
destination
3.) Finding the cheapest fare from one place to another
4.) Finding the best route to avoid traffic in the streets.
2. THE SOLUTION: BELLMAN-FORD ALGORITHM
The Bellman–Ford algorithm computes single-source shortest paths in a weighted graph.
Bellman–Ford is used primarily for graphs with negative edge weights. The algorithm is named
after its developers, Richard Bellman and Lester Ford, Jr. If a graph contains a "negative cycle",
i.e., a cycle whose edges sum to a negative value, then walks of arbitrarily low weight can be
constructed, i.e., there may be no shortest path. Bellman-Ford can detect negative cycles and
report their existence, but it cannot produce a correct answer if a negative cycle is not reachable
from the source. The Bellman-Ford algorithm detects negative weight cycles and if it detects a
negative weight cycle on the graph, then Bellman-Ford will not able to find the shortest path. It
will not able to find the shortest path because if it keeps going around the negative cycle then we
are decreasing the weight in the path so it results to –infinity as the shortest path.
Algorithm:
The Bellman-Ford algorithm is one of the classic solutions to this problem. It
calculates the shortest path to all nodes in the graph from a single source.
1.) Start by considering that the shortest path to all nodes, less the source, is infinity. Mark
the length of the path to the source as 0.
3. 2.) Take every edge and try to relax it. Relaxing an edge means checking to see if the path to
the node the edge is pointing to can’t be shortened, and if so, doing it. In the above graph,
by checking the edge 1 -> 2 of length 6, you find that the length of the shortest path
to node 1 plus the length of the edge 1 -> 2 is less then infinity. So, you replace infinity
in node 2 with 6. The same can be said for edge 1 -> 4 of length 7. It’s also worth noting
that, practically, you can’t relax the edges whose start has the shortest path of length
infinity to it.
3.) Finally, it checks for negative weight cycles on the graph. It returns TRUE if there are no
negative cycles that are reachable from source vertex and FALSE otherwise.
1
1
Bellman-Ford Algorithm.Wikipedia. Retrieved March 8,2012. From
http://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm
One Source Shortest Path: The Bellman-Ford Algorithm Retrieved March 8,2012.
Fromhttp://compprog.wordpress.com/2007/11/29/one-source-shortest-path-the-bellman-ford-algorithm/