Interval Scheduling, Matroids, and Scheduling with Deadlines
The material for interval scheduling is borrowed largely from the presentation in Klienberg Tardos, Algorithm Design.
The presentation for matroids is based on Erickson's chapter on matroids in the textbook Algorithms.
Slides made in collaboration with Claude. All the cool bits are thanks to Claude, and blame me for oversights :)
Scenario: You manage a single resource (a room, a machine, a projector...)
You receive requests to use it during specific time intervals.
Two requests are compatible if they don't overlap.
Click "New Problem" to generate intervals
Input: Set of requests \(\{1, 2, \ldots, n\}\)
Request \(i\) has start time \(s(i)\) and finish time \(f(i)\)
Compatible: Requests \(i, j\) are compatible if \(f(i) \leq s(j)\) or \(f(j) \leq s(i)\)
Goal: Find a maximum-size subset of mutually compatible requests
Let's brainstorm: what greedy rule could we use to select intervals?
Suggestions will appear here...
What greedy strategy should we use?
Running time: \(O(n \log n)\) — just sort by finish time!
We prove greedy "stays ahead" of any other solution.
Setup:
Let \(i_1, i_2, \ldots, i_k\) be greedy's choices (in order)
Let \(j_1, j_2, \ldots, j_m\) be any optimal solution (sorted)
Proof by induction:
Base case (\(r=1\)): Greedy picks the interval with earliest finish time.
So \(f(i_1) \leq f(j_1)\) for any other interval \(j_1\). ✓
Proof by induction:
Assume: \(f(i_{r-1}) \leq f(j_{r-1})\) (induction hypothesis)
1. Since \(j_r\) is compatible with \(j_{r-1}\): \(f(j_{r-1}) \leq s(j_r)\)
2. By transitivity: \(f(i_{r-1}) \leq s(j_r)\) → \(j_r\) is available to greedy!
3. Greedy picks earliest finish in available zone → \(f(i_r) \leq f(j_r)\) ✓
Proof by contradiction:
Can we identify when greedy algorithms work in general?
Goal: Find a structural property of optimization problems that guarantees greedy success.
Setup:
• A finite universe \(\mathbf{U} = \{e_1, e_2, \ldots, e_n\}\)
• A weight function \(w: \mathbf{U} \to \mathbb{Q}_{\geq 0}\)
• A family \(\mathcal{F} = \{S_1, \ldots, S_m\}\) of feasible subsets
Weight of a set: \(w(S) = \sum_{e \in S} w(e)\)
Goal: Find maximum weight set in \(\mathcal{F}\)
This looks like Kruskal's algorithm for maximum spanning trees!
Counterexample:
\(\mathbf{U} = \{p, q, r\}\)
\(w(p) = 40, \quad w(q) = 30, \quad w(r) = 20\)
\(\mathcal{F} = \{\{p\}, \{q, r\}\}\)
Greedy: Picks \(\{p\}\) → weight 40
Optimal: \(\{q, r\}\) → weight 50
Greedy is suboptimal!
Greedy choices \(g_1, \ldots, g_k\) vs Optimal choices \(o_1, \ldots, o_\ell\) (sorted by weight)
What property of \(\mathcal{F}\) makes greedy work?
Nice Family:
If \(S, T \in \mathcal{F}\) and \(|S| > |T|\),
then \(\exists e \in S \setminus T\) with \(T \cup \{e\} \in \mathcal{F}\)
Counterexample:
\(\mathbf{U} = \{p, q\}\), \(w(p) = 40\), \(w(q) = 30\)
\(\mathcal{F} = \{\{p, q\}\}\)
Greedy picks \(\emptyset\) (weight 0), but optimal is \(\{p,q\}\) (weight 70)!
Issue: Greedy's intermediate sets may not be in \(\mathcal{F}\).
We need greedy's partial solutions to always be in \(\mathcal{F}\).
Combined with exchange, this gives the right structure!
A matroid \(\mathcal{M} = (U, \mathcal{F})\) consists of:
• A finite ground set \(U\)
• A collection \(\mathcal{F}\) of subsets satisfying:
| Independent set | A set in \(\mathcal{F}\) |
| Dependent set | A subset of \(U\) not in \(\mathcal{F}\) |
| Basis | Maximal independent set |
| Rank | Size of any basis (all bases have same size!) |
| Circuit | Minimal dependent set |
Uniform matroid \(U_{k,n}\):
Ground set: \(\{1, 2, \ldots, n\}\)
Independent sets: \(X\) is independent iff \(|X| \leq k\)
Special case: \(U_{n,n}\) = free matroid (all subsets independent)
Graphic matroid \(M(G)\) for graph \(G = (V, E)\):
Ground set: Edge set \(E\)
Independent sets: Acyclic subgraphs (forests)
Kruskal's algorithm = greedy on graphic matroid!
Recall the algorithm:
Let greedy output \(G = \{g_1, g_2, \ldots, g_k\}\) (in order added)
Let \(O = \{o_1, o_2, \ldots, o_m\}\) be an optimal basis (sorted by weight)
Claim: For all \(i\): \(w(g_i) \geq w(o_i)\)
Greedy's i-th choice is at least as heavy as optimal's i-th.
Since all bases have the same size (\(k = m\)), this implies:
\(w(G) = \sum w(g_i) \geq \sum w(o_i) = w(O)\)
Suppose not: Let \(i\) be the first index where \(w(g_i) < w(o_i)\).
Consider:
\(T = \{g_1, \ldots, g_{i-1}\}\) — greedy's first \(i-1\) choices
\(S = \{o_1, \ldots, o_i\}\) — optimal's first \(i\) elements
Note: \(|S| = i > i-1 = |T|\), and both \(S, T \in \mathcal{F}\) (heredity)
We have \(o_j \in S \setminus T\) with \(T \cup \{o_j\} \in \mathcal{F}\).
Key observation:
• \(o_j \in \{o_1, \ldots, o_i\}\), so \(w(o_j) \geq w(o_i)\)
• We assumed \(w(o_i) > w(g_i)\)
• So \(w(o_j) > w(g_i)\)
Proof: If \(\mathcal{S}\) is not heriditary, then let \(S\) be any subset in \(\mathcal{S}\) which is such that there exists \(T \subset S\) and \(T \notin \mathcal{S}\). Assign:
Then \(S\) is the unique optimal solution, but greedy will never find this set.
Let \(X\) and \(Y\) be two sets in \(\mathcal{S}\) that violate the exchange property: \(|X| > |Y|\), but for any \(x \in X \setminus Y\), the set \(Y \cup \{x\} \notin \mathcal{S}\).
Let \(m = |Y|\).
Greedy accepts all of \(Y\), rejects all of \(X \setminus Y\) (infeasible), then considers other elements.
Greedy returns weight \(m(m+2) = m^2 + 2m\).
But \(X\) has weight at least \((m+1)^2 = m^2 + 2m + 1\). Contradiction!
Scenario: You have \(n\) tasks to complete in \(n\) days.
Each task requires one full day of attention.
Each task has a deadline \(d_i\) and a penalty \(p_i\).
If task \(i\) is completed after day \(d_i\), you pay penalty \(p_i\).
| Task | Deadline | Penalty |
|---|---|---|
| A | 2 | 5 |
| B | 1 | 3 |
| C | 2 | 7 |
Schedule [B, C, A]: B on day 1 ✓, C on day 2 ✓, A on day 3 ✗
Penalty = 5 (only A is late)
Schedule [A, C, B]: A on day 1 ✓, C on day 2 ✓, B on day 3 ✗
Penalty = 3 (only B is late) — Better!
Observation: The cost of a schedule is determined by which tasks are on time.
Definition: A set \(X\) of tasks is realistic if there exists a schedule where every task in \(X\) is on time.
Lemma: \(X\) is realistic if and only if \(|X(t)| \leq t\) for every \(t\),
where \(X(t) = \{i \in X : d_i \leq t\}\) (tasks with deadline ≤ t)
Intuition: Can't schedule more than $t$ tasks with deadline $\leq t$.
Theorem: The collection of realistic sets forms a matroid.
Rephrased goal: Find a realistic set \(X\) maximizing \(\sum_{i \in X} p_i\)
(Maximize penalty of on-time tasks = minimize penalty of late tasks)
GreedySchedule(tasks):
Sort tasks by penalty (decreasing)
onTime ← ∅
for each task i:
if onTime ∪ {i} is realistic:
add i to onTime
return canonical schedule for onTime
Canonical schedule: Execute on-time tasks in deadline order, then late tasks.
Running time: \(O(n^2)\), or \(O(n \log n)\) with clever data structures.