Skip to main content
Z

N-Queens Visualizer — Backtracking

Animated N-Queens backtracking on a chessboard — try, place, conflict, and backtrack with step controls. Runs in your browser.

Free No signup Client-side Privacy friendly Updated

/

Pseudocode

Press Run to animate the algorithm.

How to use

  1. 1 Press Run to place queens column by column with backtracking.
  2. 2 A blue cell is being tried; a red cell conflicts with an existing queen.
  3. 3 When a column has no safe row, the search backtracks to the previous column.
  4. 4 Use Shuffle for a different board size, or step through the search.

Why use this tool

  • See backtracking explore, hit dead ends, and undo its choices.
  • Understand the safety test: no two queens share a row, column, or diagonal.
  • A canonical constraint-satisfaction and backtracking example.
  • Runs entirely in your browser. No signup, no uploads.

Frequently asked questions

What is the N-Queens problem?

Place n queens on an n×n chessboard so that no two attack each other — no shared row, column, or diagonal.

How does backtracking solve it?

Place queens one column at a time. For each column try each row; if it is safe, recurse to the next column; if no row is safe, backtrack and try a different row in the previous column.

What is the time complexity?

Worst case is roughly O(n!), but pruning conflicting placements makes finding a single solution far faster in practice.

For which n does a solution exist?

Solutions exist for every n except 2 and 3. The classic 8-queens puzzle has 92 distinct solutions.

What is N-Queens Visualizer?

An N-Queens Visualizer animates backtracking search placing n queens on an n×n board so none attack each other. It tries each row of a column, marks conflicts, recurses when a placement is safe, and backtracks when a column has no safe row.

Features

Backtracking animation

Watch queens get placed and removed as conflicts are detected.

Complexity

Worst case exponential (≤ O(N!) placements, pruned heavily). Space: O(N).

100% private

Runs entirely in your browser — nothing is uploaded.

Example

Input

N = 4

Output

2 distinct solutions (N = 8 has 92)

Common use cases

  1. 1

    Learn backtracking

    See how constraint checking and backtracking prune the search.

  2. 2

    Constraint satisfaction

    Understand a classic CSP with row/column/diagonal constraints.

  3. 3

    Count solutions

    Explore how the number of solutions grows with N.

Summary

Zerethon's N-Queens visualizer animates the backtracking search for placing N queens on an N×N board so none attack each other, in your browser. It places queens column by column and backtracks on conflicts. The search is exponential in the worst case (bounded by O(N!) placements, far fewer with pruning); space is O(N). There are 2 solutions for N=4 and 92 for N=8.

Category
Algorithm
Pricing
Free
Privacy
Browser-based
Signup
Not required

References

Privacy

Your data never leaves your browser unless explicitly stated. N-Queens Visualizer runs entirely client-side — no server upload, no logging, no tracking of your input.

New to this? Read the step-by-step explanation with Big-O analysis: Learn Dynamic Programming →

Related tools

Build, share, and grow on Zerethon Social

Free signup. Earn points, collect achievements, and connect with creators worldwide.

Sign up free