R05 Handout
R05 Handout
Given n intervals x1 , x2 , . . . , xn where s(xi ) and f (xi ) are the starting and finishing points of
each xi , select as many of the intervals as possible without any conflicts, i.e., no two selected
intervals overlap. (Sharing one endpoint is fine. We consider two intervals overlapping if their
intersection is also a nondegenerate interval.)
From lecture, we know that greedily picking jobs with earliest finishing time is optimal. Now we consider some other greedy approaches.
For each of the following proposed greedy selection method, either argue that the algorithm is optimal or provide a counterexample,
briefly explaining where the resulting algorithm fails to be optimal.
(a) Starting with an empty solution S and input set X of intervals, repeat until X is empty: Add the shortest remaining interval to
S, then remove all intervals that it conflicts with from X.
(b) Starting with an empty solution S and input set X of intervals, repeat until X is empty: Add the remaining interval that causes
the fewest conflicts to S, breaking ties arbitrarily, then remove all intervals that it conflicts with from X.
(c) In addition to the so-called exchange argument from lecture, another technique is called “greedy stays ahead ” to prove a greedy
algorithm as optimal. Recall the correct algorithm from lecture that greedily picks the interval that with earliest finishing time.
The greedy stays ahead proof strategy intuitively means that by greedily picking intervals that end as early as possible, the greedy
algorithm has the same or more “room” to pick more intervals than any other solution.
Let us formalize this notion. Let ALG = a1 , a2 , . . . , at be the sequence of intervals chosen by the greedy algorithm, and let
OPT = o1 , o2 , . . . , om be the sequence of intervals in an optimal solution, both ordered in increasing order of finishing time.
What does “ahead” mean? Since we are greedily selecting with respect to finishing time, so we want to show f (ai ) ⩽ f (oi ) for
each i. (We later use this claim to conclude the algorithm is optimal.) We use induction. The base case f (a1 ) ⩽ f (oi ) is obvious,
since a1 ends the earliest among all intervals, so we’ll assume it is proven already!
† Prove the induction hypothesis: if f (ak ) ⩽ f (ok ) then f (ak+1 ) ⩽ f (ok+1 ).
† Prove the main claim: |OPT| ≤ |ALG|. This shows ALG is optimal.
2
Problem 2. Consider the following variant of the interval scheduling problem from lecture:
Given n intervals x1 , x2 , . . . , xn where s(xi ) and f (xi ) are the starting and finishing points
of each xi , select the smallest subset of intervals so that every interval xi conflicts with (is
“stabbed”) a selected interval.
1. Consider the following greedy strategy. Starting with an empty solution S and input set X of intervals, repeat until X is empty:
Add the longest remaining interval to S (i.e., the interval that maximizes f (i) − s(i)), then remove all intervals that it conflicts
with from X. Show that this strategy is not optimal by providing a counterexample.
Note that, in choosing xm in line 6, we include all stabbing intervals in X, marked and unmarked. By definition, the algorithm
must return a subset where each intervals is stabbed by an interval in S. But is it optimal? Finish the proof of the following
claim, implying its optimality, using the exchange argument technique.
Claim. There exists an optimal solution that contains all elements in the output set.
Proof. Let ALG = a1 , . . . , at be the sequence of intervals chosen by the algorithm, sorted in increasing order of finishing time. We
will prove by induction that, for all i ≤ t, there is an optimal solution that contains the first i intervals a1 , . . . , ai of ALG. (Note
that for i = t, this implies the original claim.)
• i > 1. By the induction hypothesis, there is an optimal solution OPT that contains a1 , . . . , ai−1 .
Consider the iteration of the algorithm in which ai was chosen, and let xℓ be the interval on line 5 of that iteration. Since
xℓ was not marked in that iteration, it is not stabbed by the first intervals a1 , . . . , ai−1 . OPT must contain some interval oj
that stabs xℓ , where oj ∈
/ a1 , . . . , ai−1 .
If ai = oj , then OPT contains a1 , . . . , ai and we are done. So suppose otherwise, ai ̸= oj . Consider the alternate solution
OPT′ obtained by exchanging oj in OPT with ai .
[(b) Prove that OPT′ is feasible; that is, it stabs all input intervals. It may be useful to draw xℓ , ai , oj , xm .]
Since OPT’ is feasible and has size |OPT| − 1 + 1 = |OPT|, it’s optimal. It also contains a1 , . . . , ai , so we are done.