Last active
January 6, 2018 14:00
-
-
Save dVakulen/fc3d4901193ec79bb48330dd9b064e26 to your computer and use it in GitHub Desktop.
Backtracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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