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.

جو کم از کم جاننا ضروری ہے

اہم علامتیں

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

مختصر حل شدہ مثال

  • 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.

عام غلطیاں

اس قسم کے سوال کو کیسے پہچانیں

Next recommended lesson

Continue through this topic with Least You Need to Know: Prefix Function, Borders, and KMP Intuition.

Least You Need to Know: Prefix Function, Borders, and KMP Intuition

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

مشق شروع کریں