Practice Discrete Math

Algorithms / Permutations Constraints Search

Least You Need to Know: Permutations, Used Sets, and Constraint Propagation

Permutation search cares about **order**, so each recursive level chooses the next position from items not yet used. Constraint checks can often be applied to the growing prefix to reject bad permutations early.

The least you need to know

Key notation

prefix already fixed first part of the permutation
used[x] whether item x is already placed
constraint propagation reject a partial permutation as soon as its prefix breaks a rule

Tiny worked example

  • To build permutations of `[1,2,3]`, choose the first position from all three items.
  • If `1` is placed first, mark it used and recurse to fill the second position from `{2,3}`.
  • After returning, unmark `1` before trying another first choice.
  • If a prefix already violates a rule, reject it before filling later positions.

Common mistakes

How to recognize this kind of problem

Start practice