I'm a bit confused about stopping at Kth iteration on the Bellman-Ford algorithm to find the shortest path of at most length k from s to t. Let me show you a graph and explain you what I understand:
At first iteration, I will have:
- Shortest path to get to A is S->A (cost 1)
- Shortest path to get to B is S->B (cost 4)
- Shortest path to get to T is still unknown
At second iteration I will have:
- Shortest path to get to A is S->A (cost 1)
- Shortest path to get to B is A->B (cost 2(A->B) + cost 1(S->A) = 3) updated!
- Shortest path to get to T is B->T
But now going to B takes 2 edges instead of 1, so going to T is 3 edges away now: S->A->B->T, and this has happened in 2 iterations.
What am I understanding wrong?