Proofs: Interval piercing greedy
These are the human proofs of Interval piercing greedy, at full length.
The piercing greedy places the fewest points full
This proof shows: correctness, termination.
We use the pseudocode of the page. The intervals are nonempty and of one type, with . Let be the order of line L1, so . For half-open and open intervals line L4 tests in place of .
Claim. PIERCE stops after steps. For closed intervals it returns a set of points that pierces every interval, of the least possible size. For half-open and open intervals the same holds after each is replaced by the real point of its group described below.
Openers and groups. Call an opener if line L5 runs in its step, and let be the openers in order, with right ends . The group is together with the intervals read after and before ; in their steps .
Lemma 1 (each group has a common point). Every interval of meets the point in the sense of its type. That is, an interval has for closed intervals, and for half-open and open intervals.
Proof. Each interval of comes at or after in the order, so . For itself, , and for half-open and open intervals, which are nonempty. For any other interval of the test of line L4 failed, so for closed intervals and for the other types.
Real points. For closed intervals the point is , which lies in every interval of by Lemma 1. For half-open and open intervals let be the largest left end in , so by Lemma 1. For half-open intervals, lies in every , since . For open intervals, the midpoint lies in every , since . So in each case one point pierces the whole group, and the groups together contain all intervals. Hence the output pierces every interval and has points.
Lemma 2 (the openers are pairwise disjoint). For , .
Proof. When is read, and the test of line L4 holds: for closed intervals, and for the other types. For , the openers come in order, so in the closed case and otherwise. Every point of is at most , and less than for half-open and open intervals; every point of is at least , and greater than it for open intervals. In each case every point of is less than every point of .
Optimality. Let be any set of points that pierces every interval. Each opener contains a point of , and by Lemma 2 no point lies in two openers. So , and the output, with points, is optimal.
Termination. Line L1 sorts keys, and the loop of line L3 does one step of work for each index. The real points need one more value per group, the running maximum , which is updated in time per step.