Professional Documents
Culture Documents
(CS210/ESO207/ESO211)
Lecture 34
Greedy strategy: a new algorithm paradigm
Part III
1
Correctness of a Greedy algorithm
the optimal solution of original instance of the problem
the optimal solution of (smaller) instance obtained by the greedy step
2
A suitable Theorem
Continuing Problem from last class
3
Minimum spanning tree
Problem Description
Input: an undirected graph G=(V,E) with w: E ,
Aim: compute a spanning tree (V,E), E E such that w()
E
is minimum.
Lemma 1 (proved in last class):
If
.
Lemma 2:
If
) is defined as:
cut(,
) = { (,) | and
or and
}
Cut-property: The least weight edge of a cut(,
) must be in MST.
13
cut(,
)
23
13
37
48
67
u
v
Pursuing greedy strategy
to minimize weight of MST,
what can we say about the
edges of cut(,
) ?
Proof of cut-property
14
23
13
37
48
67
u
v
Proof of cut-property
Let be the MST, and (u,v) .
Question: What happens if we remove (x,y) from , and add (u,v) to .
15
13
u
v
>13
x
y
Proof of cut-property
Let be the MST, and (u,v) .
Question: What happens if we remove (x,y) from , and add (u,v) to .
16
13
u
v
13
x
y
We get a spanning tree with weight < weight()
A contradiction !
Cycle Property
17
Cycle Property
Let be any cycle in .
Cycle-property:
Maximum weight edge of any cycle can not be present in MST.
18
u v
a
b
c
f
r
s
43
24
12
17
31
36
19
26
Pursuing greedy strategy
to minimize weight of MST,
what can we say about the
edges of cycle ?
Proof of Cycle property
Let be the MST, and (u,v) .
19
u v
a
b
c
f
r
s
43
24
12
17
31
36
19
26
u v
43
Proof of Cycle property
Let be the MST, and (u,v) .
20
43
24
12
17
31
36
19
u v
u v
a
b
c
f
r
s 26
43
s
36
a
24
b
12
c
17
f
31
Proof of Cycle property
Let be the MST, and (u,v) .
21
43
24
12
17
31
36
19
u v
u v
a
b
c
f
r
s 26
s
43
36
Swapping (u,v) with (f,s),
we get a spanning tree
with weight < weight()
A contradiction !
f
Algorithms based on cut Property
Spend some time on designing such an algorithm
before going to the next slide
22
How to use cut property to compute a MST ?
23
170
33
35
31
41
81
52
42
50
102
50
30
60
70
54
57
49
49
80
78
63
24
53
44
29
64
42
43
u
v
70
How to use cut property to compute a MST ?
24
170
33
31
41
81
52
42
50
102
50
30
60
70
54
57
49
49
80
78
63
24
53
44
29
64
42
43
u
v
70
35
w
How to use cut property to compute a MST ?
25
170
33
31
41
81
52
42
50
102
50
30
60
70
54
57
49
49
80
78
63
24
53
44
29
64
42
43
u
v
70
35
w
x
How to use cut property to compute a MST ?
26
170
33
31
41
81
52
42
50
102
50
30
60
70
54
57
49
49
80
78
63
24
53
44
29
64
42
43
u
v
70
35
w
x
y
How to use cut property to compute a MST ?
27
170
33
31
41
81
52
42
50
102
50
30
60
70
54
57
49
49
80
78
63
24
53
44
29
64
42
43
u
v
70
35
w
x
y
How to use cut property to compute a MST ?
28
170
33
31
41
81
52
42
50
102
50
30
60
70
54
57
49
49
80
78
63
24
53
44
29
64
42
43
u
v
70
35
w
x
y
An Algorithm based on cut property
Algorithm (Input: graph =(,) with weights on edges)
;
{u};
While ( ?? ) do
{ Compute the least weight edge from cut(,
);
Let this edge be (x,y), with x , y
;
{(x, y)};
{y};
}
Return ;
Number of iterations of the While loop : ??
Time spent in one iteration of While loop: ??
Running time of the algorithm: O()
29
O()
<>
Algorithm based on cycle Property
Spend some time on designing such an algorithm
before going to the next slide
30
An Algorithm based on cycle property
Description
Algorithm (Input: graph =(,) with weights on edges)
While ( ?? ) do
{ Compute any cycle ;
Let (u,v) be the maximum weight edge of the cycle ;
Remove (u,v) from ;
}
Return ;
Number of iterations of the While loop : ??
Time spent in one iteration of While loop: ??
Running time of the algorithm: O()
31
has any cycle
+
O()
Homework
Ponder over the following questions before coming for the next class
Use cycle property and/or cut property to design a new algorithm for MST
Use some data structure to improve the running time of the algorithms discussed in
this class to O( )
32