Two-way array partition 2026-10-24
Rearrange an array segment into a low segment containing values below a pivot and a high segment containing values at least , preserving the segment's multiset and leaving the rest of the array unchanged. The pivot need not itself occur, and either resulting segment may be empty.
An in-place scan maintains indices with and . A low value at is swapped into position and advances both indices; a high value advances only . The unexamined length is a loop variant. At exit , establishing the separation in time complexity and auxiliary space complexity. Equal values consistently belong to the high side.
An elementary union-intersection compression of a finite multiset of subsets replaces occurrences of by . A compression is a finite sequence of these moves. The move preserves every coordinate multiplicity. On incomparable sets it increases by , so repeated compression reaches a chain under inclusion. For any submodular set function, the sum of its values cannot increase.