AlgoPlus//structures / backtracking
Read the theory

Backtracking · N-Queens

Place queens row by row; back out the moment one can be attacked.

Board
6×6
Queens placed
0/6
Legend
Trying
Conflict
Placed
AI Tutor Workspace
In a nutshell
Backtracking builds an answer one decision at a time, and the instant a choice makes the rest impossible it undoes that choice and tries the next — a depth-first walk through the tree of possibilities that abandons dead branches early instead of checking every full combination. Placing queens row by row on a chessboard so none can attack each other is the classic example.
Ready
Press play to begin the cinematic walkthrough.
Build a solution choice by choice; when a choice can't lead anywhere valid, undo it (backtrack) and try the next — a guided depth-first search of the decision tree.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Backtracking · N-Queens.