This preview shows pages 1–3. Sign up to view the full content.
The University of Texas at Austin
Lecture 11
Department of Computer Sciences
Professor Vijaya Ramachandran
Greedy, MST
CS357: ALGORITHMS, Spring 2006
1
The Greedy Framework
Rcall that an
optimization problem
is one for which an input has a collection of
feasible
solutions, each with an associated cost, and we need to ﬁnd a feasible solution that
optimizes
the cost; here ‘optimizes’ would mean either
minimizes
or
maximizes
, depending on the
nature of the problem. Such a solution is called an
optimal solution.
A
greedy strategy
for an optimization problem constructs an optimal solution (which is typ
ically a set of elements)
incrementally
by making a locally optimal choice at each step to
decide the next element to be added to the solution. If this strategy generates an optimal
solution, then this represents a
greedy algorithm
.
2
A Toy Problem
Activity Selection Problem
Given a collection of activities
S
=
{
(
s
i
,f
i
), 1
≤
i
≤
n
}
,where
s
i
and
f
i
are the start and
ﬁnish times of the
i
th activity, and
f
1
≤
f
2
≤ ··· ≤
f
n
,a
feasible solution
is a subset of
activities whose durations do not overlap.
A feasible solution with the maximum number of activities is an
optimal solution
.
Algorithm
Greedy Activity Selection
Start with an initially empty solution
A
.Le
t
T
:=
S
repeat
•
Select an activity
α
in
T
with smallest ﬁnish time and set
A
:=
A
∪{
α
}
.
•
Delete from
T
those activities whose durations overlap with the selected activity.
until
T
=
φ
Correctness
Lemma 1 (Greedy Choice)
:L
e
t
X
be a subset of an optimal solution for the activity
selection problem on
S
.L
e
t
S
0
be the set of activities in
S
that do not overlap with any
activity in
X
,andl
e
t
α
=(
s, f
) be the activity with smallest ﬁnish time in
S
0
. Then,
X
0
=
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentProof.
Clearly
X
0
is a feasible solution since none of the activities in
X
0
overlap with one
another. Consider an optimal solution
A
for
S
that contains
X
. (We are given that such an
optimal solution exists.)
If
A
contains
α
then we are done. Otherwise let
β
=(
s
0
,f
0
) be the activity with smallest
ﬁnish time in
A

X
. Then,
f
0
>f
since (
s, f
) is the activity with smallest ﬁnish time
that does not overlap with any activity in
X
.S
in
c
e
α
is in
S
0
, it does not overlap with any
activity in
X
. Also,
α
does not overlap with any activity in
A

X
{
β
}
since any activity
in
A

X
{
β
}
must have a start time greater than
f
0
and the ﬁnish time
f
of
α
is smaller
than
f
0
. Hence
α
does not overlap with any activity in
A
{
β
}
.
Now consider the set
A
0
=
A
{
β
}∪{
α
}
. This is a feasible set since none of the activities
in
A
0
over
lapw
itheachother
.But

A
0

=

A

, and since
A
is an optimal solution,
A
0
is also
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '06
 Ramachandran
 Algorithms

Click to edit the document details