NIST

n queens

(classic problem)

Definition: Place n chess queens on an n × n board such that no queen can attack another. Efficiently find all possible placements.

See also 8 queens.

Note: A backtracking algorithm may be efficient enough for small values of n.

Author: PEB

Implementation

Barzan "Tony" Antal's backtracking (or depth-first) solution (C++), which has an explanation.

More information

animation (Java)


Go to the Dictionary of Algorithms and Data Structures home page.

If you have suggestions, corrections, or comments, please get in touch with Paul E. Black.

Entry modified 29 April 2010.
HTML page formatted Tue Dec 6 16:16:32 2011.

Cite this as:
Paul E. Black, "n queens", in Dictionary of Algorithms and Data Structures [online], Paul E. Black, ed., U.S. National Institute of Standards and Technology. 29 April 2010. (accessed TODAY) Available from: http://www.nist.gov/dads/HTML/nqueens.html

to NIST home page