Backtracking

Explores possible choices and goes back when a path does not work.

Choices

1
2
3

Current Path

Start exploring choices.

Solutions Found

Where It's Used

  • Problems that require exploring multiple combinations.
  • Generating permutations or subsets.
  • Constraint based search problems.
  • Exploring solution spaces where invalid paths must be abandoned.

Problems Using This Pattern

Permutations

Backtracking

Subsets

Backtracking

Combination Sum

Backtracking

Word Search

Backtracking

N Queens

Backtracking