Bell Man ford algorithm[2]
Bell Man ford algorithm[2]
ALGORITHM
MADE BY:- SAPTARSHI GHOSH
PRESENTED BY:- ABHAY PANDEY
WHAT IS BELL MAN FORD ALGORITHM
•The Bellman-Ford algorithm finds the shortest path from a single source
vertex to all other vertices in a weighted, directed graph.
- Given a graph with vertices and weighted edges, the task is to find the shortest path from
a source vertex to all other vertices.
ALGORITHM OVERVIEW
•Input: A graph G=(V,E)G = (V, E)G=(V,E) with a source vertex S, and edge
weights w(u,v).
•Output: Shortest path from the source vertex S to all other vertices.
•Properties:
•Can detect negative weight cycles.
•Initialization:
-Set the distance to the source vertex S as 0:
dist[s]=0.
- For each edge (u,v) in the graph, update the distance to v if a shorter path is found via
u:
dist [v]=min( dist[v], dist [u] + w(u,v) )
-Repeat this process for V−1 iterations (where V is the number of vertices in the graph).
•Check for Negative Weight Cycles:
-After V−1 iterations, iterate over all edges again. If any distance can still be updated, a
negative weight cycle exists in the graph.
EXAMPLE:-
Let's consider the source vertex as 'A'; therefore, the
distance value at vertex A is 0 and the distance value at
all the other vertices as infinity shown as below:
THANK YOU