Click to See Complete Forum and Search --> : Graph Problem


M_Persian
December 31st, 2006, 05:49 PM
I have an unsolved problem in graphs...its related to Bellman-Ford algorithm
I actually dont understand the meaning of this question
So i would be thankful if someone helps me with that :)
Given a weighted ,directed graph G=(V,E) with no negative-weight cycles,let m be the maximum over all pairs of vertices u,v which belong to V of the minimum number of edges in a shortest path from u to v.(Here the shortest path is by weight,not the number of edges).Suggest a simple change to the Bellman-Ford algorithm that allows it to terminate in m+1 passes.
(this exercise is of the chapter 24 of the book 'Introduction to algorithms' by CLR)
Thanks

Zachm
January 2nd, 2007, 04:16 PM
Explanation (I hope it's easy to understand):
m is simply the number of edges in the longest (in edges) lightest(in weight) path in the graph between any two vertices.
If you iterate over all pairs of vertices and check the length of the lightest path between them, then the maximum length you'll find is m.

Now for the solution:
According to Bellman-Ford algorithm proof (http://en.wikipedia.org/wiki/Bellman-Ford_algorithm), after m cycles, the weight of the path found so far from the source S to an arbitrary vertex U is at most the weight of the lightest path from S to U that uses at most m edges.

Since we know that the longest(in edges) lightest path from any vertex to any vertex is m, we can stop iterating after m cycles and add the check for negative cycles to give the complexity of m+1.

I think that this solution is good enough, given that m is known in advance.

Good luck !