Proofs: Weighted interval scheduling dynamic programming
These are the human proofs of Weighted interval scheduling dynamic programming, at full length.
The weighted interval DP returns a disjoint set of largest weight full
This proof shows: correctness, termination.
We use the pseudocode of the page. After line L1 the intervals are with , all of one type, with weights . Say that ends in time for when for half-open and open intervals and for closed intervals; this is the test counted on line L2. For a set of indices let . A set is feasible when its intervals are pairwise disjoint. Let be the largest weight of a feasible subset of , with .
Lemma 1 (disjoint means ends in time). For , if and only if ends in time for .
Proof. If ends in time, every point of is at most , and less than for half-open and open intervals, while every point of is at least , and greater than for open intervals. In each type the two sets are separated, so they are disjoint. Conversely, suppose that does not end in time: for closed intervals, for the others. Since , . For closed intervals, the point lies in both: it is at least both left ends and at most , because and . For half-open and open intervals, let ; then , since and , and the points strictly between and lie in both intervals.
Lemma 2 (prefix). The indices that end in time for are exactly , and .
Proof. If ends in time for , then : for closed intervals , and for the others . So in the sorted order, whatever the order of equal right ends. The test "ends in time" depends on only through a threshold, or , and the are sorted, so the indices that pass form a prefix, of length by line L2. Index itself fails, so .
Lemma 3 (recurrence). For , .
Proof. () A feasible subset of is a feasible subset of . If is a feasible subset of , then by Lemmas 2 and 1 every interval of is disjoint from , so is feasible, with weight .
() Let be a feasible subset of with . If , then and . If , every other has and is disjoint from , so by Lemmas 1 and 2, . So is a feasible subset of , and .
Theorem 1 (the table). After lines L3 to L5, for .
Proof. By induction on . . For , line L5 reads and with by Lemma 2, which equal and by induction, so by Lemma 3.
Theorem 2 (the traceback). Lines L6 to L9 terminate and return a feasible set with .
Proof. Invariant at the test of line L7: (a) , and (b) is feasible and every interval of is disjoint from every with .
It holds at the start with and . Suppose it holds with .
Line L8 takes . Then , so by line L5, , and , which is (a). By (b), is disjoint from every interval of , so is feasible. For , is disjoint from by Lemmas 2 and 1, and from every interval of by (b), since . So (b) holds with in place of .
Line L9 skips . Then , so , and (a) holds for . (b) holds for since it held for .
Each pass lowers , by Lemma 2 in the first case, so the loop stops with . Then (a) gives by Theorem 1, and (b) says that is feasible.
Termination of the rest. Line L1 sorts keys, line L2 does binary searches, and the loop of line L4 runs times.