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 and . Write for the number of entries that are not yet assigned.
Seeds. Lines L1 and L2 compute the waste of every pair and keep a pair whose waste is the largest; and each start with one of the two, and .
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, and are disjoint and their union is the input.
Termination. Each pass of the loop either stops at line L4 or lowers by 1, and the loop ends when . So there are at most passes.
Minimum fill. We show that at the end and . Let for .
Claim: at the start of each pass of line L3 in which line L4 does not fire, and ; and at the start of every pass, and . At the start, , since and . Suppose a pass starts with . If line L4 fires, the loop stops. Otherwise and , so and . The pass moves one entry to one group: the sum of that group does not change, and the sum of the other group drops by 1, so both are still at least at the start of the next pass. This proves the claim.
Now look at how the loop ends. If line L4 fires for group , then and the entries go to , so ; the other group has by the claim, and since entries leave the remaining set and none join , its final size is . We need . The two groups and the remaining entries add up to , so , using . If instead the loop ends with , then for both groups by the claim.
So the output is a partition of the input into two groups of at least entries, whose first entries are a pair of largest waste.