Polynomial Time Algorithms For The N-Queen Problem: Rok Sosic and Jun Gu

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 22

Polynomial Time Algorithms

for the N-Queen Problem

Rok sosic and Jun Gu


Outline
 N-Queen Problem
 Previous Works
 Probabilistic Local Search Algorithms
 QS1, QS2, QS3 and QS4
 Results
N-Queen Problem
 A classical combinatorial problem
 n x n chess board
 n queens on the same board
 Queen attacks other at the same row, column
or diagonal line
 No 2 queens attack each other
A Solution for 6-Queen
Previous Works
 Analytical solution
 Direct computation, very fast
 Generate only a very restricted class of
solutions
 Backtracking Search
 Generate all possible solutions
 Exponential time complexity
 Can only solve for n<100
QS1
 Data Structure
 The i-th queen is placed at row i and column queen[i]
 1 queen per row
 The array queen must contain a permutation of
integers {1,…,n}
 1 queen per column

 2 arrays, dn and dp, of size 2n-1 keep track of number


of queen on negative and positive diagonal lines
 The i-th queen is counted at dn[i+queen[i]] and

dp[i-queen[i]]
 Problem remains
 Resolve any collision on the diagonal lines
QS1
 Pseudo-code
QS1
 Gradient-Based Heuristic
QS2
 Data Structure
 Queen placement same as QS1
 An array attack is maintained
 Store the row indexes of queens that are under
attack
QS2
 Pseudo-code
QS2

Go through the
attacking queen only

Reduce cost of bookeeping

C2=32 to maximize the speed for


small N, no effect on large N
QS3
 Improvement on QS2
 Random permutation generates
approximately 0.53n collisions
 Conflict-free initialization
 The position of a new queen is randomly
generated until a conflict-free place is found
 After a certain of queens, m, the remaining c
queens are placed randomly regardless of
conflicts
QS4
 Algorithm same as QS1
 Initialization same as QS4
 The fastest algorithm
 3,000,000 queens in less than one minute
Results – Statistics of QS1
Collisions for random permutation

Max no. and min no. of queens on the most populated diagonal
in a random permutation

Permutation Statistics

Swap Statistics
Results – Statistics of QS2
Permutation Statistics

Swap Statistics
Results – Statistics of QS3
Swap Statistics

Number of conflict-free queens during initialization


Results – Time Complexity
Results – Time Complexity
Results – Time Complexity
Results – Time Complexity
Results – Time Complexity
References
 R. Sosic, and J. Gu, “A polynomial time
algorithm for the n-queens problem,” SIGART
Bulletin, vol.1(3), Oct. 1990, pp.7-11.
 R. Sosic, and J. Gu, “Fast Search Algorithms
for the N-Queens Problem,” IEEE
Transactions on Systems, Man, and
Cybernetics, vol.21(6), Nov. 1991, pp.1572-
1576.
 R. Sosic, and J. Gu, “3,000,000 Queens in
Less Than One Minute,” SIGART Bulletin,
vol.2(2), Apr. 1991, pp.22-24.

You might also like