Generate all valid arrangements using backtracking with pruning. Use when solving permutations, combinations, subsets, N-queens, sudoku, or constraint satisfaction problems.
Scanned 9/7/2026
Install to Claude Code
npx -y skills add knoopx/pi --skill recursion-backtracking --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Recursion Backtracking?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/knoopx-recursion-backtracking)More formats (shields.io, HTML) on the badges page.
---
name: recursion-backtracking
description: "Generate all valid arrangements using backtracking with pruning. Use when solving permutations, combinations, subsets, N-queens, sudoku, or constraint satisfaction problems."
topic: Backtracking
token_cost: 100
related: [dynamic-programming, dfs-vs-bfs]
keywords:
[
permutation,
combination,
subset,
backtrack,
constraint,
generate,
valid,
recursive,
pruning,
n-queens,
sudoku,
exhaustive,
all,
solutions,
choose,
pick,
arrangement,
password,
sequence,
]
---
## When to use
Use backtracking for constraint satisfaction and combinatorial generation: permutations, combinations, subsets, N-queens, sudoku, valid arrangements.
## Rules
- Pattern: make a choice, recurse, undo the choice (backtrack)
- Prune early — skip branches that already violate constraints to avoid exploring dead ends
- For subsets: at each element, choose to include or exclude it (2^n total)
- For permutations: choose each unused element at each position (n! total)
- ALWAYS pass state by reference and undo mutations rather than copying
- NEVER copy state — it's wasteful and slow
- If the problem says "generate all" or "find all valid," backtracking is usually the right approach
## Complexity
Subsets: 2^n. Permutations: n!.
## Example
Subsets of [1,2,3]: at each element, branch include/exclude. `def solve(i): if i==n: yield list(path); return; path.append(nums[i]); solve(i+1); path.pop(); solve(i+1)`.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!