Algorithm Search⌘K

Proofs: Interval partitioning greedy

These are the human proofs of Interval partitioning greedy, at full length.

The partitioning greedy uses exactly as many resources as the depth full

This proof shows: correctness, termination.

We use the pseudocode of the page. The intervals I[1],…,I[n]I[1], \ldots, I[n] are nonempty and of one type, with I[j]=⟨lj,rj⟩I[j] = \langle l_j, r_j \rangle. Say that an interval ⟨l′,r′⟩\langle l', r' \rangle is over by xx when r′≤xr' \le x for half-open and open intervals and r′<xr' < x for closed intervals. Line L4 tests whether the interval at the heap minimum is over by I[j].lI[j].l. Let dd be the depth, the largest number of intervals that contain one point.

Lemma 1 (over by means disjoint). Let A=⟨a,a′⟩A = \langle a, a' \rangle and B=⟨b,b′⟩B = \langle b, b' \rangle with a≤ba \le b. Then A∩B=∅A \cap B = \emptyset if and only if AA is over by bb.

Proof. For closed intervals, A∩B=∅A \cap B = \emptyset if and only if a′<ba' < b, since a≤ba \le b and BB contains bb. For half-open intervals, BB contains bb and the points just right of it, and AA contains every point of [a,a′)[a, a'), so they are disjoint if and only if a′≤ba' \le b. For open intervals, BB contains the points just right of bb, and AA contains every point of (a,a′)(a, a'); if a′>ba' > b, the points just right of bb and left of a′a' are in both, since a≤ba \le b, and if a′≤ba' \le b every point of AA is less than bb. □\square

Lemma 2 (two intervals through a point). Under the same assumption a≤ba \le b, if AA is not over by bb, then AA and BB both contain the point z(b)z(b). Here z(b)=bz(b) = b for closed and half-open intervals. For open intervals, z(b)z(b) is a fixed point with b<z(b)b < z(b) and no end point of any input interval in (b,z(b)](b, z(b)]; it exists because there are finitely many end points.

Proof. For closed intervals, a≤b≤a′a \le b \le a' and b≤b′b \le b', so b∈A∩Bb \in A \cap B. For half-open intervals, a≤b<a′a \le b < a' and b<b′b < b', so b∈A∩Bb \in A \cap B. For open intervals, a≤b<a′a \le b < a' and b<b′b < b'. The end points a′a' and b′b' are greater than bb, so z(b)<min⁡(a′,b′)z(b) < \min(a', b'), and a≤b<z(b)a \le b < z(b); so z(b)∈A∩Bz(b) \in A \cap B. □\square

Invariant. Let DD be the set of indices processed so far. Before each step of the loop of line L3:

(I) The heap holds exactly one pair (t,c)(t, c) for each c∈{1,…,k}c \in \{1, \ldots, k\}, where tt is the right end of the interval last(c)last(c), the interval of DD with label cc that was processed last. Two intervals of DD with the same label are disjoint.

Initialization. DD is empty, k=0k = 0 and the heap is empty.

Maintenance. Let jj be the next index, x=I[j].lx = I[j].l. Every interval of DD starts at or before xx, by the order of line L1.

Line L5 runs. The minimum pair is (t,c)(t, c), and last(c)last(c) is over by xx. The intervals with label cc, in processing order, are A1,…,Am=last(c)A_1, \ldots, A_m = last(c), and Ai+1A_{i+1} took label cc when AiA_i was over by l(Ai+1)l(A_{i+1}), so r(Ai)≤l(Ai+1)≤r(Ai+1)r(A_i) \le l(A_{i+1}) \le r(A_{i+1}). So every AiA_i has r(Ai)≤tr(A_i) \le t and is over by xx whenever last(c)last(c) is: if r(Ai)≤tr(A_i) \le t and t≤xt \le x (or t<xt < x), the same holds for r(Ai)r(A_i). By Lemma 1, each AiA_i is disjoint from I[j]I[j]. Line L7 gives I[j]I[j] label cc and puts (rj,c)(r_j, c) back, so (I) holds.

Line L6 runs. Then I[j]I[j] gets the new label k+1k + 1, which no other interval has, and line L7 adds its pair. (I) holds.

Optimality. Consider the step in which line L6 opens resource kk, at x=I[j].lx = I[j].l. If the heap is not empty, its minimum is not over by xx, so no pair is: each last(c)last(c) for c<kc < k has right end at least the minimum, so it is not over by xx either. Each last(c)last(c) starts at or before xx. By Lemma 2, applied to last(c)last(c) and I[j]I[j], each last(c)last(c) and I[j]I[j] contain the point z(x)z(x), which depends only on xx. So kk intervals contain one point, and k≤dk \le d. On the other side, the dd intervals through one point pairwise meet, so a valid labeling gives them dd different labels, and every valid labeling has at least dd labels. The final kk is the largest value opened, so k=dk = d, and by (I) at the end the labeling is valid.

Termination. Line L1 sorts nn keys. The loop runs nn times, each with at most one EXTRACT-MIN and one INSERT on a heap of at most nn pairs. ■\blacksquare

Back to Interval partitioning greedy