Given the following problem :
Given the directed graph G=(V,E) with the weight function W:V→R , describe an algorithm
that find the shortest paths from S to all other Vertices , where the length of the
path equals to the SUM of all the vertices.You need to change an existing algorithm ,
to make that work , so there’s no need to write a new algorithm.
Please notice that the weight function is on the Vertices and NOT(!!) on the Edges .
What I was thinking is to change the Bellman-Ford algorithm and change the Relax check to the following :
1.if d[v]>d[u]+w[u]
1.1 d[v] <<-- d[u]+w[u]
1.2 PI[v] <<-- u
I don’t think this works good enough , any idea what might be the problem ?
thanks ,Ron
let
w:V->Rbe your weight function.Create a weightening function:
w':E->Ras follows:w'(u,v) = w(v)Run dijkstra/bellman-ford with w’. let d'[v] be the minimal path’s weight to v, according to w’.
Then if the shortest path is
s->u1->u2->...->un->v, you get:d'[v] = w'(s,u1) + w'(u1,u2) + ... + w'(un,v)[by correctness of dijkstra/bellman fofrd] and thusd'[v] = w(u1) + w(u2) + ... + w(un) + w(v)[by definition of w’].so, at overall you get:
d[v] = w(s) d'[v]and d[v] is the shortest path for vertices.