Please wait
Loading technology simulations
The requested content is still loading.
Finished experimenting?
Save one completion to this browser's signed guest ledger, or directly to your account when signed in.
Please wait
Loading technology simulations
The requested content is still loading.
Save one completion to this browser's signed guest ledger, or directly to your account when signed in.
1solve(row):2 if row == n: return true // all placed3 for col in 0 .. n−1:4 if not safe(row, col): skip5 place queen at (row, col)6 if solve(row+1): return true7 remove queen (backtrack)
This N-Queens simulator makes backtracking tangible. Press Play and queens drop into the board row by row; the moment a partial board has a conflict the search prunes that branch and backtracks, visibly removing a queen — with attacked squares shaded red so you see exactly why. A search-space card contrasts the brute-force nn boards and the n! column permutations against the handful of nodes backtracking actually visits (for n = 8 that's ~16.7 million versus a couple thousand). The signature interaction: switch to Solve-It-Yourself and place queens by clicking squares, with attacking pairs turning red in real time and a success banner when you arrange n queens with no shared row, column, or diagonal. A synced pseudocode panel highlights the try, place, and backtrack lines as the search runs.
backtracking · n-queens problem · constraint satisfaction · search tree pruning · recursion · exponential search space · depth-first search
Browse all Technology simulations →
Free to use in your browser — no signup required. Found a bug or have an idea to make it better? Tell us.