To provide a formal proof by contradiction for the optimality of the greedy algorithm in selecting non-overlapping intervals, let's restate the problem and provide the proof in a structured way:
Problem Restatement
We are given a collection of intervals ([a_i, b_i]), and we want to remove the fewest number of intervals so that the remaining intervals do not overlap. The greedy algorithm suggests sorting intervals by their end times and iteratively picking intervals that start after or when the last picked interval ends.
Proof by Contradiction
Theorem: The greedy algorithm is optimal for selecting the maximum number of non-overlapping intervals (or equivalently, removing the minimum number of overlapping intervals).
Proof: Assume, for the sake of contradiction, that the greedy algorithm is not optimal. Suppose the greedy method selects a set of intervals (G = {g_1, g_2, \ldots, g_k}), and there exists an optimal solution (O = {o_1, o_2, \ldots, o_m}) such that (m > k) (i.e., the optimal solution picks more non-overlapping intervals).
Let's align the sequences such that (g_i = o_i) for as many steps as possible, say for the first (r) intervals, i.e., (g_1 = o_1, g_2 = o_2, \ldots, g_r = o_r), where (r) is as large as possible and less than (m).
-
Case at (r+1): By the assumption, since (O) has an additional interval (o_{r+1}) which is not in (G), the first interval (o_{r+1}) that differs between the optimal and greedy solution must be chosen differently.
-
Properties of the Intervals Chosen:
- Each of the chosen intervals is non-overlapping with the previous ones. So, (b(g_r) \leq a(o_{r+1})), ensuring that interval (o_{r+1}) starts after or exactly when the (r)-th interval picked by the greedy ends.
-
Contradictory Interval Existence:
- The greedy method would have had the chance to pick (o_{r+1}), as it dilutes the space between the preceding choice (g_r) and any successive choice (g_{r+1}), assuming it exists.
- If greedy did not pick (o_{r+1}), then it must have picked another interval (g_{r+1}) before (o_{r+1}), such that (b(g_{r+1}) < b(o_{r+1})). This contradicts the sorted order chosen by greedy as per end times.
Since by contradiction, such a set (O) cannot exist where the number of non-overlapping intervals exceeds the greedy solution while adhering to this sorted order and picking intervals based on earliest finish times, the assumption that a better (optimal) solution exists without using greedy choices fails.
Thus, the greedy algorithm is indeed optimal for this interval scheduling problem.
Conclusion: The proof shows by contradiction that any deviation from the greedy choice produces a non-optimal solution. Hence, the greedy algorithm must be optimal in removing the minimum number of overlapping intervals, ensuring non-overlapping remains.