8 Queens 2-D
Continuing our exploration of backtracking, we redo the 8 Queens Problem in a 2-D setting.
This time around, we are going to be using goto statements .
Template using goto statements
Here is a visual to demonstrate the algorithm we will use.
Take note of how the algorithm moves through the board. Could you write down the steps it does exactly?
How the algorithm should move: Show
1) Start queen at the top of the current column (if this is our first time we are starting in the first column).
2) check to see if the current space is ok
2.1) check diagonalUp
2.2) check Left
2.3) check diagonalDown
3) If it is ok, move to next column and start from 1.
4) If it is not ok, move to next row and start from 2.
5) If during this process, we move beyond the last row, we backtrack
6) If during this process, we move beyond the last column, we have found 1 solution.