Global AI and Data Science

Global AI & Data Science

Train, tune and distribute models with generative AI and machine learning capabilities

 View Only

Eight Queens Puzzle

By Moloy De posted Sat October 14, 2023 12:17 AM

  
The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other; thus, a solution requires that no two queens share the same row, column, or diagonal. There are 92 solutions. The problem was first posed in the mid-19th century. In the modern era, it is often used as an example problem for various computer programming techniques.
 
The eight queens puzzle is a special case of the more general n queens problem of placing n non-attacking queens on an n×n chessboard. Solutions exist for all natural numbers n with the exception of n = 2 and n = 3. Although the exact number of solutions is only known for n ≤ 27, the asymptotic growth rate of the number of solutions is approximately (0.143 n)n.
 
Chess composer Max Bezzel published the eight queens puzzle in 1848. Franz Nauck published the first solutions in 1850. Nauck also extended the puzzle to the n queens problem, with n queens on a chessboard of n×n squares.
 
Since then, many mathematicians, including Carl Friedrich Gauss, have worked on both the eight queens puzzle and its generalized n-queens version. In 1874, S. Gunther proposed a method using determinants to find solutions. J.W.L. Glaisher refined Gunther's approach.
 
In 1972, Edsger Dijkstra used this problem to illustrate the power of what he called structured programming. He published a highly detailed description of a depth-first backtracking algorithm.
Finding all solutions to the eight queens puzzle is a good example of a simple but nontrivial problem. For this reason, it is often used as an example problem for various programming techniques, including nontraditional approaches such as constraint programming, logic programming or genetic algorithms. Most often, it is used as an example of a problem that can be solved with a recursive algorithm, by phrasing the n queens problem inductively in terms of adding a single queen to any solution to the problem of placing n−1 queens on an n×n chessboard. The induction bottoms out with the solution to the 'problem' of placing 0 queens on the chessboard, which is the empty chessboard.
 
This technique can be used in a way that is much more efficient than the naïve brute-force search algorithm, which considers all 648 = 248 = 281,474,976,710,656 possible blind placements of eight queens, and then filters these to remove all placements that place two queens either on the same square leaving only 64!/56! = 178,462,987,637,760 possible placements or in mutually attacking positions. This very poor algorithm will, among other things, produce the same results over and over again in all the different permutations of the assignments of the eight queens, as well as repeating the same computations over and over again for the different sub-sets of each solution. A better brute-force algorithm places a single queen on each row, leading to only 88 = 224 = 16,777,216 blind placements.


QUESTION I: What is the minimum number of Queens needed with which one can cover every square of chess board?
QUESTION II: What is the probability of placing n non-attacking Queens in an n×n chessboard? Is it a constant?

REFERENCE: Wikipedia

1 comment
11 views

Permalink

Comments

Mon May 19, 2025 03:49 PM

Fascinating deep dive into the eight queens puzzle — it's incredible how a problem that looks simple on the surface ends up intersecting so many areas of math and computer science. Found a similar kind of fun on this answers site recently — different genre, but definitely gets the brain working.

For Question I: If we're talking about covering (attacking or occupying) every square of the board rather than solving the classic "non-attacking" puzzle, then the minimum number of queens needed to cover every square on an 8×8 chessboard is 5. This is a classic problem in itself and has been proven through exhaustive checks and various configurations.

For Question II: The probability of placing n non-attacking queens on an n×n board isn't constant and gets trickier as n increases. There’s no straightforward closed-form formula for it, and the likelihood drops quickly for large n due to the complexity of valid configurations. While there are always solutions for n ≥ 4, the number of possible placements increases much faster than the number of valid solutions, so the "probability" in a random placement scenario becomes quite small.