(800 Views)

**Problem Statement:** Place n-queens in n x n chessboard so that no two of them can attack each other i.e no two of them are on the same row, column or diagonal. In this problem backtracking is done to solve the problem. solutions of this problems are expressed in n-tuple.

In the above algorithm,

- For the n queen problem we take input of n, lets say n=4 so, k=1,2,3,4.
- For placing the first queen i.e k=1,we start a loop for n columns i.e n=4 so till the fourth column.
- The first queen can be placed at first column only.
- Then we move for the second queen and place it seeing that the first queen is not in the same column or in diagonal with the second queen.
- Similarly, the third queen and the fourth queen are placed. But if the fourth queen cannot be placed as it lies in same column or is in diagonal with other queens then back-tracking is done to the previous queens inorder of 3,2,1 to achieve the unique feasible solution.
- For an n problem queen the same way all the n queens are placed and if the n
^{th}cannot be placed back-tracking is done and the queens are re-ordered and solution is obtained.

0 UpvotesUpvote |
0 DownvotesDownvote |

- Import Git project in Eclipse [1152 Views]
- Floyd Warshalls Algorithm [224 Views]
- Create an Augmented Reality (AR) Android App using Unity and Artoolkit [6566 Views]
- Download AngularJS Up & Running by Shyam Seshadri & Brad Green PDF [2676 Views]
- Pseudocode And Flowchart for Generating 100 Prime Numbers [1944 Views]

- How To Win Ludo King Game Every Time [31962 Views]
- Algorithm to find whether number is Armstrong Number or Not [30440 Views]
- Knuth-Morris-Pratt (KMP) Substring Search Algorithm with Java Example [24942 Views]
- Jio Phone hang on LOGO problem Solution - Hard Reset Jio Phone [21832 Views]
- FlowChart and Algorithm to find Whether a Number is Even or Odd [16276 Views]