Try → Check → Go deeper → Undo
Backtracking = DFS on a decision tree with undo.
Where am I in the problem?
row · vertex · position
What can I try now?
column · color · next node
Is this choice valid?
isSafe / valid()
Undo the last choice and try the next.
unchoose / remove
solve(state):
if solution found:
output solution
return
for each choice:
if not valid(choice):
continue
make choice
solve(next state)
undo choice // restore state for next choice
Same look, better logic: DFS goes down one branch, fails or succeeds, then comes back.
| Problem | State | Choice | Constraint |
|---|---|---|---|
| N-Queens | current row | column | queen must be safe |
| Graph Coloring | current vertex | color | adjacent vertices cannot match |
| Hamiltonian Cycle | path position | next vertex | edge must exist, vertex not repeated |
If students remember only one thing from this page, it should be this line.