Practice Discrete Math

Algorithms / Partitioning Dutch Flag

Least You Need to Know: Partitioning Invariants and Dutch-Flag Regions

Partition algorithms maintain region invariants while scanning an unknown middle segment. This is the interview core behind quickselect-style partitioning, Dutch-flag sorting, and in-place grouping by a pivot or category.

The least you need to know

Key notation

< pivot | = pivot | unknown | > pivot Dutch-flag region layout
low, mid, high region boundaries for three-way partitioning
unknown region segment not yet classified

Tiny worked example

  • Keep `[0, low)` as values less than the pivot and `(high, end)` as values greater than the pivot.
  • Let `mid` scan the unknown region.
  • A small value swaps left and advances both `low` and `mid`.
  • A large value swaps right and shrinks `high`, but `mid` stays to inspect the new value.

Common mistakes

How to recognize this kind of problem

Start practice