Two-way array partition

ID: two-way-array-partition

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.

New to topics? Read the docs here!