0% found this document useful (0 votes)
2 views2 pages

R05 Handout

The document discusses greedy algorithms for the interval selection problem, focusing on selecting non-overlapping intervals and proving optimality through various strategies. It presents different greedy approaches, analyzes their effectiveness, and provides a proof structure for optimal solutions using induction and exchange arguments. The document also explores a variant of the problem involving 'stabbing' intervals and evaluates the optimality of proposed greedy strategies.

Uploaded by

benmatz132
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

R05 Handout

The document discusses greedy algorithms for the interval selection problem, focusing on selecting non-overlapping intervals and proving optimality through various strategies. It presents different greedy approaches, analyzes their effectiveness, and provides a proof structure for optimal solutions using induction and exchange arguments. The document also explores a variant of the problem involving 'stabbing' intervals and evaluates the optimality of proposed greedy strategies.

Uploaded by

benmatz132
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1

CS 330, Recitation 05, 10/7/2024: Greedy Algorithms


Problem 1. Consider the interval selection problem again.

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.

2. Consider another greedy strategy, as follows.

Algorithm 1: Smallest Stabbing Schedule


1 Start with the empty set S = ∅ of intervals.
2 Initially, all intervals are unmarked.
3 Sort the intervals of X = x1 , x2 , . . . , xn in increasing order of finishing time.
4 while X ̸= ∅ do
5 Remove xℓ from X. If xℓ is already marked, continue to the next iteration.
6 Among all intervals in X that stabs xℓ , pick xm to be the one that ends last (i.e., maximizes
f (xm )).
7 Add xm to S, then mark all intervals in X stabbed by xm , including xm (and xℓ ).
8 return S.

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. [(a) Prove this base case by showing an optimal solution contains a1 .]

• 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.

You might also like