Level 2 · Core Data StructuresBUILD 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 MODELWhen 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.