Skip to content

Swaps [mp]

Micro pattern

Description

Exchange two positions or semantic states in constant time to restore an invariant.

Problems

Comparison sorting

Exchange elements to place them in appropriate regions.

Reversal and rotation

Swap symmetric positions while moving inward.

In-place partitioning

Swap values into their target regions or natural positions.

Permutation generation

Swap remaining values into positions and undo swaps after exploration.

Constant-time unordered deletion

Replace a removed array slot with its final element.

Swap semantic extremes

Exchange minimum and maximum summaries when their roles reverse.