https://github.com/emahtab/bellman-ford-algorithm
https://github.com/emahtab/bellman-ford-algorithm
bellman-ford-algorithm graph shortest-path
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/emahtab/bellman-ford-algorithm
- Owner: eMahtab
- Created: 2022-01-02T04:44:27.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-02T05:32:34.000Z (over 4 years ago)
- Last Synced: 2025-02-02T03:25:53.222Z (over 1 year ago)
- Topics: bellman-ford-algorithm, graph, shortest-path
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bellman Ford Algorithm
Bellman Ford algorithm is used to find the shortest path in a weighted graph from a source vertex.
❗❗❗ Remember Bellman Ford algorithm works with negative weights.
## Algorithm :
1. Take a `distances[]` array and fill it with `Integer.MAX_VALUE` , set `distances[startingVertex] = 0`
2. Sort the given edges according to edge weights
3. If number of vertices are n, loop over edges **n-1** times (Outer loop)
4. Loop over all the given edges(u,v) and relax (check if `dU + dUV < dV`) the vertices if possible (Inner loop) and update the distances[v] accordingly.
5. At the end `distances` array will have **shortest path** to all the vertices from the `startingVertex`
# References :
https://www.youtube.com/watch?v=IjEX4rgxsvI (Hindi, Good explanation)