Skip to content

NelsonBN/algorithms-data-structures-bellman-ford

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

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

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
Loading

With negative cycles

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
Loading

Demos

References

About

Algorithms and Data Structures - Bellman-Ford

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages