All-Pairs Shortest Path

90 Views Asked by At

Based on Bellman-Ford, I need to develop an algorithm that determines the length of the shortest path(s) between $v_1, v_2$ with a maximum of $2^k$ edges. I first thought of running Bellman-Ford for every node, but I don't know how to implement the edge limitation. If I stop the algorithm at the k'th iteration, I would end with paths of length $k$.

1

There are 1 best solutions below

0
On

No path can have length more than $n$, so you can stop Bellman-Ford after $\min \{ n, 2^k \}$ iterations.