Backtracking - N Queens Problem | Algorithms
by SJ · May 10, 2015 Objective : In chess, a queen can move as far as she pleases, horizontally, vertically, or diagonally. A chess board has 8 rows and 8 columns. The standard 8 by 8 Queen's problem asks how to place 8 queens on an ordinary chess board so that none of them can hit any other in one move.(Source: http://www.math.utah.edu/~alfeld/queens/queens.html) Here we are solving it for N queens in NxN chess board. N Queens Problem Approach: Create a solution matrix of the same structure as chess board. Whenever place a queen in the chess board, mark that particular cell in solution matrix. At the end print the solution matrix, the marked cells will show the positions of the queens in the chess board. Algorithm: Place the queens column wise, start from the left most column If all queens are placed. return true and print the solution matrix. Else Try all the rows in the current column.Read full article from Backtracking - N Queens Problem | Algorithms
No comments:
Post a Comment