Suppose we are given a directed graph G = (V, E)
with potentially positive and negative edge lengths, but no negative cycles. Let s ∈ V
be a given
Here`s O(k(|V | + |E|)) approach:
Because any s-u shortest path is atmost k edges, we can end algorithm after k iterations over edges
Pseudocode:
for each vertex v in vertices:
D[v] := +ooD[s] = 0
repeat k times:
for each edge (u, v) with weight w in edges:
if D[u] + w < D[v]:
D[v] = D[u] + w