eight queens puzzle

(redirected from N-queens)

eight queens puzzle

A puzzle in which one has to place eight queens on a chessboard such that no queen is attacking any other, i.e. no two queens occupy the same row, column or diagonal. One may have to produce all possible such configurations or just one.

It is a common students assignment to devise a program to solve the eight queens puzzle. The brute force algorithm tries all 64*63*62*61*60*59*58*57 = 178,462,987,637,760 possible layouts of eight pieces on a chessboard to see which ones meet the criterion. More intelligent algorithms use the fact that there are only ten positions for the first queen that are not reflections of each other, and that the first queen leaves at most 42 safe squares, giving only 10*42*41*40*39*38*37*36 = 1,359,707,731,200 layouts to try, and so on.

The puzzle may be varied with different number of pieces and different size boards.

References in periodicals archive ?
Due space reasons we show only experimental results measured in number of backtracks but the conclusion is the same using other performance metrics (nodes visited, time): for each problem the dynamic approach gains very good position in the global ranking (it was the best for N-Queens n=8; the second for N-Queens n=16, N-Queens n=20 and Magic Square n=3; and rank fourth for Magic Square n=4).
Number of Backtracks solving N-Queens (NQ) and Magic Square (MS) with different strategies Strategy NQ n=8 NQ n=16 NQ n=20 MS n=3 MS n=4 F + ID 10 542 10026 0 12 F + IDM 11 542 10026 1 51 MRV + ID 10 3 11 0 3 MRV + IDM 10 3 11 1 97 AMRV + ID 11 517 2539 4 1191 AMRV + IDM 11 517 2539 0 42 O + ID 10 542 10026 0 10 O + IDM 10 542 10026 1 29 Dynamic 6 404 629 1 23
The N-queens problem consists in placing N queens on an NxN board in such a way that they do not attacks one another [5][7][12].
An initial solution to the N-queens problem, using an sequential algorithm, consists in trying all possible location combinations of the queens on the board, keeping those that are valid and disrupting the search whenever this is not achieved.
Pure parallel solution (without considering work distribution) for the type of problems where Tp>>Tc, mainly the N-Queens requires a minimal communication among machines, thus making essential the choice of data distribution among clusters, to achieve an almost optimal Speedup.
For example, there are several orders of magnitude between the first and first- fail pure strategies in the n-queens problem.
We tested our strategies on several instances of the n-queen problem and of Latin squares.