21 Greedy
21 Greedy
Greedy Algorithms
Algorithms
0 if Sij
Recursive c[i, j ]
max{c[i, k ] c[k , j ] 1} if Sij
Solution: ik j
a 1
3 -3
d e f
0
:=;
AA:= ;
while
whileAAnot
notcomplete
completetree
treedo
do
find
findaasafe
safeedge
edge(u,
(u,v);
v);
AA:=:=AA{(u,
{(u,v)}
v)}
od
od
a
5
b 7 c a light edge crossing cut
(could be more than one)
1 -3
11 3
cut partitions vertices into
d
0
e
2
f disjoint sets, S and V – S.
Corollary:
Corollary:IfIf(u,
(u,v)
v)isisaalight
lightedge
edgeconnecting
connectingoneoneCC
CCin
in(V,
(V,A)
A)
to
toanother
anotherCC
CCin in(V,
(V,A),
A),then
then(u,
(u,v)
v)isissafe
safefor
forA.
A.
Not in tree
a/0 5 b/ 7 c/
11 3 1 -3 Q=a b c d e f
0
d/ e/ f/
0 2
11 3 1 -3 Q=b d c e f
5 11
d/11 e/ f/
0 2
11 3 1 -3 Q=e c d f
3 7 11
d/11 e/3 f/
0 2
11 3 1 -3 Q=d c f
0 1 2
d/0 e/3 f/2
0 2
11 3 1 -3 Q=c f
1 2
d/0 e/3 f/2
0 2
11 3 1 -3 Q=f
-3
d/0 e/3 f/-3
0 2
11 3 1 -3 Q=
d/0 e/3 f/-3
0 2
3 1 -3