Your current MST T
contains n-1
edges. The addition to your graph of the new edge e = (u,v)
with weight w
creates exactly one cycle C
in the graph T + e
(T
with edge e
added). If the new edge weight (w
) is less than the weight of the highest-weight edge in this cycle C
, then you can create a lower weight MST by replacing that higher-weight edge with e
. Otherwise, your current MST remains optimal.
The algorithm is basically this:
- Find the unique path
P
from u
to v
in T
- Find the edge
e*
in P
that has maximum weight w*
- Is
w < w*
?
- If so, then
T' = T - e* + e
is the MST for G + e
,
with weight(T') = weight(T) - w* + w
- If not, then
T' = T
is the MST of G + e