N-Queens Visualizer
Place queens row by row, reject attacked squares, and watch backtracking discover valid N-Queens boards.
Board setup
Step controls
Step 1 of 95: Start solving 4-Queens by placing one queen per row.
N-Queens board
Start solving 4-Queens by placing one queen per row.
Call stack
Solutions
What is an N-Queens Visualizer?
An N-Queens visualizer shows how backtracking places queens on an N by N chessboard so no two queens share a row, column, or diagonal.
This tool steps through each placement attempt, rejection, queen placement, solution, and backtrack. It highlights attacked squares so the pruning logic is visible.
For the full cluster of related tools, browse the Data Structure Visualizers hub.
How to use this N-Queens visualizer
- Choose a board size from 4 to 8.
- Step through row-by-row queen placement.
- Watch rejected squares when a column or diagonal is attacked.
- Run to the end to record solutions.
- Compare the board with the call stack and solution list.
N-Queens backtracking idea
The solver places one queen per row. For each row, it tries every column. If a column or diagonal is already occupied, that square is rejected. If a square is safe, the queen is placed and the solver moves to the next row.
When a row has no safe column, the solver removes the previous queen and tries the next column. This is the backtracking step.
Compare this page with the Backtracking Visualizer, Recursion Tree Visualizer, and Matrix Traversal Visualizer.