0e_disj-intv
0e_disj-intv
Yufei Tao
1/11
Yufei Tao Activity Selection
In this lecture, we will commence our discussion of greedy algorithms,
which enforce a simple strategy: make the locally optimal decision at
each step. Although this strategy does not always guarantee finding a
globally optimal solution, sometimes it does. The nontrivial part is to
prove (or disprove) the global optimality.
2/11
Yufei Tao Activity Selection
Activity Selection
Input: A set S of n intervals of the form [s, f ] where s and f are integers.
Output: A subset T of disjoint intervals in S with the largest size |T |.
3/11
Yufei Tao Activity Selection
Activity Selection
Example: Suppose
S = {[1, 9], [3, 7], [6, 20], [12, 19], [15, 17], [18, 22], [21, 24]}.
4/11
Yufei Tao Activity Selection
Activity Selection
Algorithm
Repeat until S becomes empty:
Add to T the interval I ∈ S with the smallest finish time.
Remove from S all the intervals intersecting I (including I itself)
5/11
Yufei Tao Activity Selection
Activity Selection
Example: Suppose S = {[1, 9], [3, 7], [6, 20], [12, 19], [15, 17], [18, 22],
[21, 24]}.
We first add [3, 7] to T , after which intervals [3, 7], [1, 9] and [6, 20]
are removed. Now S becomes {[15, 17], [12, 19], [18, 22], [21, 24]}.
The next interval added to T is [15, 17], which shrinks S further to
{[18, 22], [21, 24]}. After [18, 22] is added to T , S becomes empty
and the algorithm terminates.
6/11
Yufei Tao Activity Selection
Next, we will prove that the algorithm returns an optimal solution. Let us
start with a crucial claim.
We will prove that all the intervals in T are disjoint. This indicates that
T is also an optimal solution, and hence, will complete the proof.
7/11
Yufei Tao Activity Selection
It suffices to prove that I1 cannot intersect with any other interval in
J ∈ T . This is true because
the start time of J is after the finish time of I1′ ;
the finish time of Ik is less than or equal to the finish time of I1′ .
8/11
Yufei Tao Activity Selection
Claim 2: Let I1 , I2 , ..., Ik be the first k ≥ 2 intervals picked by our
algorithm (in the order shown). Assume that there is an optimal
solution containing I1 , ..., Ik−1 . Then, there must exist an optimal
solution containing I1 , ..., Ik−1 , Ik .
All the intervals in T ∗ \ {I1 , ..., Ik−1 } must start strictly after the
finish time of Ik−1 .
9/11
Yufei Tao Activity Selection
If Ik ∈ T ∗ , Claim 2 is true and we are done. Next, we consider the case
where Ik ∈/ T ∗.
Let Ik′ be the interval in T ∗ \ {I1 , ..., Ik−1 } that has the smallest finish
time. Construct a set T of intervals as follows: add all the intervals of
T ∗ to T except Ik′ , and finally add Ik to T .
10/11
Yufei Tao Activity Selection
Activity Selection
11/11
Yufei Tao Activity Selection