Algorithm Search⌘K

Proofs: Quadratic split

These are the human proofs of Quadratic split, at full length.

The quadratic split returns two groups of at least m entries, with seeds of largest waste full

This proof shows: correctness, termination.

Let n≥2n \ge 2 and 1≤m≤n/21 \le m \le n/2. Write rr for the number of entries that are not yet assigned.

Seeds. Lines L1 and L2 compute the waste of every pair i<ji < j and keep a pair whose waste is the largest; G1G_1 and G2G_2 each start with one of the two, and r=n−2r = n - 2.

Partition. Each step of the loop moves exactly one entry from the remaining set to one group (line L7), or moves all remaining entries to one group and stops (line L4). An entry is never moved twice. So at the end, G1G_1 and G2G_2 are disjoint and their union is the input.

Termination. Each pass of the loop either stops at line L4 or lowers rr by 1, and the loop ends when r=0r = 0. So there are at most n−2n - 2 passes.

Minimum fill. We show that at the end ∣G1∣≥m|G_1| \ge m and ∣G2∣≥m|G_2| \ge m. Let sk=∣Gk∣+rs_k = |G_k| + r for k=1,2k = 1, 2.

Claim: at the start of each pass of line L3 in which line L4 does not fire, s1>ms_1 > m and s2>ms_2 > m; and at the start of every pass, s1≥ms_1 \ge m and s2≥ms_2 \ge m. At the start, s1=s2=1+(n−2)=n−1≥2m−1≥ms_1 = s_2 = 1 + (n - 2) = n - 1 \ge 2m - 1 \ge m, since n≥2mn \ge 2m and m≥1m \ge 1. Suppose a pass starts with s1,s2≥ms_1, s_2 \ge m. If line L4 fires, the loop stops. Otherwise s1≠ms_1 \ne m and s2≠ms_2 \ne m, so s1>ms_1 > m and s2>ms_2 > m. The pass moves one entry to one group: the sum sks_k of that group does not change, and the sum of the other group drops by 1, so both are still at least mm at the start of the next pass. This proves the claim.

Now look at how the loop ends. If line L4 fires for group kk, then ∣Gk∣+r=m|G_k| + r = m and the rr entries go to GkG_k, so ∣Gk∣=m|G_k| = m; the other group jj has sj≥ms_j \ge m by the claim, and since rr entries leave the remaining set and none join GjG_j, its final size is sj−rs_j - r. We need sj−r≥ms_j - r \ge m. The two groups and the remaining entries add up to nn, so sj−r=∣Gj∣=n−∣Gk∣−r=n−m≥ms_j - r = |G_j| = n - |G_k| - r = n - m \ge m, using n≥2mn \ge 2m. If instead the loop ends with r=0r = 0, then ∣Gk∣=sk≥m|G_k| = s_k \ge m for both groups by the claim.

So the output is a partition of the input into two groups of at least mm entries, whose first entries are a pair of largest waste. ■\blacksquare

Back to Quadratic split