Math Fundamentals18 sections · 814 units
Open in Course

Pattern - Backtracking for Permutations

(General template)

Backtracking for permutations follows this template:

1.1. If current solution is complete, save it

2.2. Loop through all candidates for the next position

3.3. If candidate is valid (not used, not duplicate), add it

4.4. Recurse

5.5. Backtrack (remove candidate, mark as unused)

This pattern works for permutations, combinations, subsets, and more.