recursion-backtracking

Installation
SKILL.md

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

Installs
2
Repository
knoopx/pi
GitHub Stars
59
First Seen
May 24, 2026
recursion-backtracking — knoopx/pi