Skip to content

Instantly share code, notes, and snippets.

@dVakulen
Last active January 6, 2018 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dVakulen/fc3d4901193ec79bb48330dd9b064e26 to your computer and use it in GitHub Desktop.
Save dVakulen/fc3d4901193ec79bb48330dd9b064e26 to your computer and use it in GitHub Desktop.
Backtracking
1) Start in the leftmost column
2) If all queens are placed
return true
3) Try all rows in the current column. Do following
for every tried row.
a) If the queen can be placed safely in this row
then mark this as part of the
solution and recursively check if placing
queen here leads to a solution.
b) If placing queen in leads to a
solution then return true.
c) If placing queen doesn't lead to a solution
then unmark this
and go to step (a) to try other rows.
3) If all rows have been tried and nothing worked,
return false to trigger backtracking.
(https://www.geeksforgeeks.org/printing-solutions-n-queen-problem/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment