Eight Queens Problem — Definition, Formula & Examples
The Eight Queens Problem is the challenge of placing eight chess queens on a standard 8×8 chessboard so that no two queens threaten each other — meaning no two share the same row, column, or diagonal.
The Eight Queens Problem asks for all arrangements of 8 non-attacking queens on an board, where two queens attack each other if they occupy the same row, column, or diagonal. It is a specific instance of the more general -queens problem on an board and serves as a classic constraint-satisfaction problem in combinatorics and computer science.
How It Works
Since each row must contain exactly one queen, you can think of a solution as choosing one column for each row. Start by placing a queen in row 1, then try to place one in row 2 that doesn't conflict. If you reach a row where no safe column exists, backtrack and move the previous queen. This trial-and-error strategy is called backtracking. A computer can systematically explore all possibilities this way. For the 8×8 board, there are exactly 92 distinct solutions (or 12 if you count rotations and reflections as equivalent).
Worked Example
Problem: Verify that the following placement is valid for the first 4 rows: queen in row 1 at column 2, row 2 at column 4, row 3 at column 6, row 4 at column 8.
Step 1: Check columns: the queens occupy columns 2, 4, 6, and 8 — all distinct, so no column conflict.
Step 2: Check diagonals using the rule that two queens at positions and share a diagonal if . Compare every pair:
Step 3: Continue checking the remaining pairs: (2,4)→(3,6): ✓; (2,4)→(4,8): ✓; (3,6)→(4,8): ✓. No diagonal conflicts exist either.
Answer: The partial placement is valid — no two of these four queens attack each other. You would continue placing queens in rows 5 through 8 using the same checks.
Why It Matters
The Eight Queens Problem is a gateway to understanding backtracking algorithms, which appear throughout computer science courses and coding interviews. It also illustrates constraint-satisfaction problems that arise in scheduling, circuit design, and resource allocation.
Common Mistakes
Mistake: Forgetting to check diagonals and only verifying that no two queens share a row or column.
Correction: Queens also attack along diagonals. Always verify that for every pair of queens.
