WorkspaceLearning path
Level 2 · Core Data Structures
BUILD YOUR INTUITION

Backtracking

Explore a decision tree by choosing an option, solving the smaller remaining task, and undoing the choice before trying another option.

THE MENTAL MODEL

When should this come to mind?

Explore a decision tree by choosing an option, solving the smaller remaining task, and undoing the choice before trying another option.

Enumerate combinationsGenerate valid stringsAll subsetsPrune invalid prefixes

What makes it work

Each recursive call needs a progress measure; every mutation shared by branches must be undone. Copy paths when saving them.

When to choose something else

Enumeration can require exponentially many outputs. Counting or optimization may allow DP instead.

See the pattern in action

Change the input. Follow the state. Make it yours.