algorithm - Find the minimum weight cycle that contains a specific edge -
given graph: - oriented, - connected , - weighed (the weights positive) have write function taken input edge (u, v), calculate weight of cycle of minimum weight contains edge.
i thought i'd follows procedure inaccurate , incomplete: - starts bfs visit starting node u - keep in variable temporary weight - when arrive v choose minimum of previous weights. how keep track of previous weights? how write pseudocode?
i have no idea how started me?
thanks
this can reduced shortest path problem:
find shortest path v u, shortest cycle contains (u,v), v->...->u->v, v->...->u shortest path v u found shortest path algorithm.
it can solved efficiently using dijkstra's algorithm, since there no negative weights in graph.
correctness proof:
assume there cheaper cycle v1->v2->...vi->u->v->v_i+1->...->vn->v1. let's weights x < d(v,u) + w(u,v)
since it's cycle, can @ v->v_i+1->....->vn->v1->...->vi->u->v.
the weight of cycle didn't change, , still x. means x=w(v,v_i+1) + ... + w(vn,v1) + ... + w(v_i-1,vi) + w(vi,u) + w(u,v)
but gives w(v,v_i+1) + ... + w(vn,v1) + ... + w(v_i-1,vi) + w(vi,u) + w(u,v) - w(u,v) < d(v,u), , have found shorter path v u, d(v,u), contradicting correctness of dijkstra's algorithm.
qed
Comments
Post a Comment