#partition
Array Partition
Array Partition Array partition rearranges elements so that all elements satisfying a predicate come before those that do not. The operation runs in-place and does not require additional storage. You use it as a primitive in selection, quicksort, filtering, and grouping tasks. Problem Given an array $A$ of length $n$ and a predicate $P(x)$, reorder the array so that: for all indices $i < k$, $P(A[i])$ holds for all indices...
Stable Partition
Stable Partition Stable partition rearranges an array so that elements satisfying a predicate appear before the others, while preserving relative order inside both groups. You use it when grouping is required but original order still carries meaning. Problem Given an array $A$ of length $n$ and a predicate $P(x)$, reorder the array so that: all elements satisfying $P$ appear first all elements not satisfying $P$ appear after them relative order...