I used to be given an train to show that the Bellman-Ford algorithm, with sustaining a predecessor array for the vertices, permits discovering a adverse weight cycle within the graph.
I ought to emphasize that the aim of the train is to show that we will recuperate mentioned cycle, not solely that it exists.
I must show the next:
- If at any second p[v] = u then d[v] ≥ d[u] + w(u,v)
- A cycle in mother or father pointers is a adverse weight cycle.
- If an edge (u,v) was relaxed within the Nth iteration then following mother or father pointers from v will give us a mother or father pointer cycle (The cycle does not have to start out and finish with v in fact).
I had no hassle proving 1 and a pair of, but I am actually caught in the way to take care of the third.
It appears I am lacking one thing that derives from the relief of (u,v) within the last iteration.