# Backtracking Search

> Source: https://modeladay.com/models/backtracking-search/
> Category: principle | Topics: cognition, decision, systems | Difficulty: 3/5

## Definition

Backtracking builds a candidate solution one choice at a time and checks constraints as it goes. When a branch cannot work, it undoes the most recent choice and its consequences and tries another option at that junction.

## Core Rule

Backtracking builds a candidate solution one choice at a time and checks constraints as it goes. When a branch cannot work, it undoes the most recent choice and its consequences and tries another option at that junction.

## Opening Context

Say you're scheduling a full day of talks, three sessions in the morning and three in the afternoon. You need hosts, people at check-in, and someone to run the equipment. Each person gets one job for the day, and nobody but Li can run the demo. At the final slot, you see you've put Li on morning check-in.

You look down at a sheet that's almost full. Do you erase the whole thing, or can you go back far enough to change just part of it?

Backtracking Search is a way to try choices one at a time and step back to the last place where you still have an option. Let's walk back through the schedule and see how much of it you can keep. Then we'll look at what makes the way back take so long.

## How It Works (Preview)

Stop at the slot you can't fill and look back through the choices you made. Each time you fill a slot, check whether the arrangement can still meet the rules. If it can't, undo the latest choice and what it changed. If that slot has a name you haven't tried, see whether that person can do it instead.

Picture hitting a dead end in a maze. There may still be a path at the junction you just passed, so walk back and take a turn you haven't tried. Mark the turns you've already taken so you don't walk into the same dead end again.

## When It Fails (Preview)

Stepping back only saves time if you can use your rules to tell which way to go. The search becomes harder when the rules are wrong or you can't check them early.

## Full Lesson, Audio & Practice

Get the full Backtracking Search breakdown, 5-minute audio lesson, interactive mechanism animation, and decision checklist in the ConceptFlow app:
- iOS App Store: https://apps.apple.com/app/conceptflow-mental-models/id6756862333
- Google Play: https://play.google.com/store/apps/details?id=com.juxianyp.conceptflow
- Web page: https://modeladay.com/models/backtracking-search/

## Related Mental Models

- [Constraint Propagation](https://modeladay.com/models/constraint-propagation/)
- [Divide and Conquer](https://modeladay.com/models/divide-and-conquer/)
- [Issue Tree](https://modeladay.com/models/issue-tree/)
