Template:
function backtrack(state, choices):
if state is complete:
record solution
return
for choice in choices:
if valid:
make choice
backtrack(new state, remaining)
undo choice
Key elements: State: partial solution
Choices: what to add next
Constraints: which choices valid
Goal: when complete
"Undo choice" is what makes it backtracking.