AlgoScope

N-Queens

AlgorithmintermediateBacktracking

Place one queen per row; a column or diagonal conflict forces backtracking.

Decision · step 2 of 32Backtracking: 4 queens, with backtracking
012301231✓

Row 0, square (0, 0): no queen shares its column or a diagonal. Place a queen and move to row 1.

Open in the player →or start at step 2

What you will see

Queens placed row by row on a board; attacked squares are shaded; a dead row lifts the previous queen.

How backtracking works →

Cost

BestO(n!)
AverageO(n!)
WorstO(n!)
SpaceO(n)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Each node of the decision tree announces the choice made and whether it led to success, failure or further choices.

Reduced motion: Tree nodes appear and grey out in place; no travelling focus.

Leads to

Topics that need this one first.

Taught by the same lesson

Backtracking covers these too, in the same run.