https://github.com/nelsonbn/algorithms-data-structures-bellman-ford
Algorithms and Data Structures - Bellman-Ford
https://github.com/nelsonbn/algorithms-data-structures-bellman-ford
algorithms algorithms-and-data-structures data-structures
Last synced: 12 months ago
JSON representation
Algorithms and Data Structures - Bellman-Ford
- Host: GitHub
- URL: https://github.com/nelsonbn/algorithms-data-structures-bellman-ford
- Owner: NelsonBN
- License: mit
- Created: 2025-02-03T21:51:32.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-02T13:27:51.000Z (about 1 year ago)
- Last Synced: 2025-03-02T14:28:30.513Z (about 1 year ago)
- Topics: algorithms, algorithms-and-data-structures, data-structures
- Language: Python
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Algorithms and Data Structures - Bellman-Ford
## Characteristics
- Time complexity:
- Best: O(V) (when there are no negative edges and the shortest path is found in the first iteration)
- Average: O(V)
- Worst: O(V x E)
- Worst: O(V x E) (when all edges need to be relaxed in every iteration)
- Space complexity: O(V) (storing distances and predecessors)
## Graphs
### No negative cycles
```mermaid
graph LR
A -->|4| B
A -->|2| D
B -->|2| C
B -->|3| D
B -->|3| E
D -->|1| B
D -->|6| C
D -->|4| E
E -->|-5| C
```
### With negative cycles
```mermaid
graph LR
A -->|4| B
A -->|2| D
B -->|2| C
B -->|3| D
B -->|3| E
C -->|4| D
D -->|1| B
D -->|4| E
E -->|-9| C
```
## Demos
- [Distances](./src/distances.py)
- [Distances with improved](./src/distances_improved.py)
- [Paths](./src/paths.py)
## References
- [Other Algorithms & Data Structures](https://github.com/NelsonBN/algorithms-data-structures)