Graph/bellman_ford library
🧮 Bellman-Ford Algorithm (Single-Source Shortest Paths)
Computes shortest path distances from start to all nodes for graphs with
possibly negative edge weights. Detects negative weight cycles and throws
StateError in that case.
- Input:
nodesset andedgeslist - Time complexity: O(V·E)
- Space complexity: O(V)
Example:
final nodes = {'A','B','C','D'};
final edges = [
WeightedEdge('A','B',1), WeightedEdge('B','C',2),
WeightedEdge('A','C',4), WeightedEdge('C','D',1),
];
final dist = bellmanFord(nodes, edges, 'A');
// dist: {'A':0, 'B':1, 'C':3, 'D':4}
Functions
-
bellmanFord<
T> (Set< T> nodes, List<WeightedEdge< edges, T start) → Map<T> >T, num>