N-queens problem
The n-queens problem is the puzzle of placing n queens on an n-by-n chessboard so that no two queens attack each other.
Quantum Programming in Depth
The N queens puzzle is the problem of placing N chess queens on an N-by-N board so that no two queens attack each other.
- How it is used
- Frames Grover search as a constraint-satisfaction task requiring a representation, state preparation, and marking oracle.
- How deep it goes
- Derives three encodings, their search spaces and oracle checks, then compares resource estimates for a 10-queen instance.
- Examples
- Uses valid and invalid 4 × 4 placements and evaluates alternative quantum encodings for 10 queens.
- What you can do after
- Evaluate encoding tradeoffs by relating constraint structure to oracle complexity, register size, and estimated quantum resources.
Read how Quantum Programming in Depth explains n-queens problem →
Optimization Algorithms: AI techniques for design, planning, and control problems
The n-queens problem is the puzzle of placing n queens on an n-by-n chessboard so that no two queens share a row, column, or diagonal.
- How it is used
- Uses queen placement as a compact constraint-satisfaction example and as a test problem for tabu search.
- How deep it goes
- Defines the constraints, works through six tabu-search iterations, and supplies Python functions, but does not develop formal correctness proofs.
- Examples
- Demonstrates 4-by-4 and 7-queens boards, collision-count reductions, swap moves, figures, and Python-generated configurations.
- What you can do after
- Apply it via Python by representing configurations, counting attacks, exploring moves, maintaining tabu tenure, and stopping after non-improvement.
Related concepts
- constraint-satisfaction problemkind of · A constraint-satisfaction problem is a problem defined by variables, domains of possible values, and constraints, with the goal of finding an assignment that satisfies the constraints.
- tabu searchuses · Tabu search is a memory-guided local search technique that restricts recently used moves or solutions to discourage cycling and escape local optima.
- problemkind of · A problem is a difficulty, obstacle, or undesirable condition requiring investigation, mitigation, or resolution.
- OR-Toolsaddressed by · OR-Tools is an open-source software suite for solving combinatorial optimization, constraint programming, linear programming, and related problems.
- local searchaddressed by · Local search is an optimization technique that iteratively modifies a candidate solution by exploring neighboring alternatives according to an improvement rule.
- brute-force searchaddressed by · Brute-force search systematically tests many or all candidates in a defined search space, without relying on selective shortcuts to narrow it.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

