bellman_ford, a Python code which implements the Bellman-Ford algorithm for finding the shortest distance from a given node to all other nodes in a directed graph whose edges have been assigned real-valued lengths.


The computer code and data files described and made available on this web page are distributed under the MIT license


bellman_ford is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

Related Data and Programs:

dijkstra, a Python code which implements a simple version of Dijkstra's minimum distance algorithm for graphs.

toms097, a Python code which computes the distance between all pairs of nodes in a directed graph with weighted edges, using Floyd's algorithm.


  1. Richard Bellman,
    On a routing problem,
    Quarterly of Applied Mathematics,
    Volume 16, 1958, pages 87-90.
  2. Lester Ford,
    Network Flow Theory,
    RAND Corporation Paper P-923, 1956.

Source Code:

Last revised on 18 January 2020.