Skip to content

Instantly share code, notes, and snippets.

@mbchoa
Created July 24, 2020 08:00
Show Gist options
  • Select an option

  • Save mbchoa/b5c3c3c857274fddd76e72a5a46eaed8 to your computer and use it in GitHub Desktop.

Select an option

Save mbchoa/b5c3c3c857274fddd76e72a5a46eaed8 to your computer and use it in GitHub Desktop.
Pseudocode describing general structure of a recursive backtracker
bool Solve(configuration conf) {
if (no more choices) { // base case
return (conf is goal state)
}
for (all available choices) {
try one choice C:
// solve here, if it works, you're done
if (Solve(conf with choice C made) return true;
undo choice C
}
return false // tried all choices, no solution found, backtrack
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment