This preview shows pages 1–2. Sign up to view the full content.
1. Algorithm
:
01. function transform(G, M, e)
02.
if e is in M already then
03.
if e.cost < old cost then
04.
// return the same minimum spanning tree
05.
return M
06.
else
07.
remove e from M
08.
let n = e.cost
09.
let e' = e
10.
// calculate the two strongly connected components
11.
do a DFS starting with the first vertex of e and mark every
node in firstcomponent set
12.
do a second DFS starting with the second vertex of e and mark
each node in the secondcomponent set
13.
foreach edge e2 in G's edge list do
14.
if the first vertex in e2 is in firstcomponent and
second in secondcomponent
15.
or vice versa then
16.
if e2.cost < n then
17.
e' = e2
18.
n = e2.cost
19.
end
20.
end
21.
end
22.
add e' into M and return M
23.
end
24.
else
25.
if e.cost < old cost then
26.
add e into M
27.
do a DFS on M starting with one of the nodes in e and
terminate when we reach the other node of e. Mark each edge it encounters in
the set cycleedges, including e
28.
find the maximum edge in cycleedges and remove it from M
29.
return M
30.
else
31.
return M
32.
end
33.
end
34. end
Description
: Given inputs G the graph, M the minimum spanning tree, and e the edge we
altered, then we look at four different cases:
•
If e was originally in M and e’s new cost < old cost, then nothing was altered and we just
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08
 KLEINBERG
 Algorithms

Click to edit the document details