This preview shows pages 1–3. Sign up to view the full content.
The University of Texas at Austin
Lectures 1114
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 Fnd 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
Fnish 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
. Let
T
:=
S
repeat
•
Select an activity
α
in
T
with smallest Fnish time and set
A
:=
A
∪ {
α
}
.
•
Delete from
T
those activities whose durations overlap with the selected activity.
until
T
=
φ
Correctness
Lemma 1 (Greedy Choice)
: Let
X
be a subset of an optimal solution for the activity
selection problem on
S
. Let
S
′
be the set of activities in
S
that do not overlap with any
activity in
X
, and let
α
= (
s,f
) be the activity with smallest Fnish time in
S
′
. Then,
X
′
=
X
∪ {
α
}
is a subset of an optimal solution for
S
.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentProof.
Clearly
X
′
is a feasible solution since none of the activities in
X
′
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
′
,f
′
) be the activity with smallest
Fnish time in
A
−
X
. Then,
f
′
> f
since (
s,f
) is the activity with smallest Fnish time
that does not overlap with any activity in
X
. Since
α
is in
S
′
, 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
′
and the Fnish time
f
of
α
is smaller
than
f
′
. Hence
α
does not overlap with any activity in
A
− {
β
}
.
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