Skip to content

Commit c66639e

Browse files
committed
N-queen problem README file updated
1 parent 2b6ec08 commit c66639e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed
9.59 KB
Loading
914 KB
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## N-queen problem
2+
3+
The **N queens puzzle** is the problem of placing N chess queens on an n×n chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagonal. Solutions exist for all natural numbers n with the exception of n=2 and n=3.
4+
5+
![N-queen Problem ](Eight-queen.png)
6+
7+
*The only symmetrical solution to the eight queens puzzle (except for rotations and reflections of itself)*
8+
9+
10+
### Backtracking Algorithm
11+
The idea is to place queens one by one in different rows, starting from the first row. When we place a queen in a row, we check for clashes with already placed queens. In the current row, if we find a column for which there is no clash, we mark this row and column as part of the solution. If we do not find such a column due to clashes then we backtrack.
12+
13+
This algorithm of solving this problem is known as a 'depth-first search' or 'Backtracking' approach. This is much better than the naive approach where all possible arrangements of the queens need to produce and then check if it is a valid solution.
14+
15+
![N-queen Problem visualization ](Eight-queens-animation.gif)
16+
17+
### More on this topic
18+
- https://en.wikipedia.org/wiki/Eight_queens_puzzle
19+
- http://www.geeksforgeeks.org/backtracking-set-3-n-queen-problem/
20+
- https://developers.google.com/optimization/puzzles/queens

0 commit comments

Comments
 (0)