#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
♛ FREE · STEP BY STEP

N-Queens Backtracking Visualizer: See Backtracking Think

Choose a board size and replay how queens are placed row by row, rejected when attacked, and removed when a row has no safe square.

  • ♟️ 4×4 to 10×10 boards
  • ↩️ Every backtrack shown
  • 🔢 Total solutions

How to use the N-Queens Backtracking Visualizer

  1. 1. Set it upPick the board size n, from 4 to 10.
  2. 2. RunPress Solve to find the first solution and count all of them.
  3. 3. ReplayStep or play through each placement; attacked squares turn red.

Worked example: 6 queens

On a 6×6 board the first solution places queens in columns 2, 4, 6, 1, 3, 5 (row 1 to row 6). Getting there takes 197 recorded steps of placing, rejecting attacked squares and backtracking. Counting every solution, there are exactly 4, found after trying 894 squares. For the classic 8×8 board there are 92 solutions; for 4×4 there are 2, and 2×2 and 3×3 have none.

How backtracking works here

The solver puts one queen in each row, trying columns left to right. A square is safe if no earlier queen shares its column or diagonal; on a diagonal, the difference in rows equals the difference in columns. If no column in the current row is safe, it goes back to the previous row, removes that queen and tries the next column. The replay marks the rejected square with ✕ and the queen that attacks it in red, so you see exactly why each choice failed.

Why interviewers ask it

N-Queens is the standard example of backtracking: build a solution step by step and undo the last step at a dead end. The same template solves Sudoku, permutations, combination sums and word search. The worst case grows roughly like n!, but pruning attacked squares early cuts the search enormously. You can see this in how few squares are tried compared with all possible placements.

Frequently asked questions

Why can't I choose n = 2 or 3?

Those boards have no solution. n = 1 is trivial, so the tool starts at 4.

Is only the first solution replayed?

Yes, to keep the replay short. The total count covers all solutions.

Why stop at 10?

Bigger boards still solve, but the replay becomes too long to follow.

Is the N-Queens visualizer free?

Yes. You can use the N-Queens visualizer without signing up. The first time you run it, we ask once for your name and WhatsApp number; after that the N-Queens visualizer and every other Uncodemy tool open straight away.

More free tools

See all free tools