INTERMEDIATE · 10 MIN · FREE LESSON
Backtracking
Explore backtracking through a visual, step-by-step model.
Loading interactive lesson…
INTERMEDIATE · 10 MIN · FREE LESSON
Explore backtracking through a visual, step-by-step model.
Loading interactive lesson…
Use {"mode":"queens","n":4}, {"mode":"subsets","values":[1,2,3]}, {"mode":"permutations","values":[1,2,3]}, or a 9×9 Sudoku board with 0 for blanks. Sudoku has a bounded search budget and reports when exhausted.
Keep partial choices separate from committed solutions.
Choose a candidate, test constraints, recurse, then undo that choice. Pruning avoids invalid branches, but enumeration must still pay for its output. A budget limit is not proof of unsatisfiability.
Measured reads + comparisons, seed 42. Plotted sample sizes respect each lesson’s explicit input limits.
Keyboard: Space play/pause · ←/→ step · R restart · 1–5 speed. Reduced motion disables transitions.
Explore a maze of partial answers, returning to exactly the same junction before trying another branch.
Choose, test, recurse, undo. Change the input to test a base case, a repeated subproblem and an unreachable or constrained state where applicable.
Predict a recurrence choice, comparison or valid search branch. Explain which stored state or constraint makes the next decision correct.
Output/search dependent; exponential or factorial worst-case. The player states the recurrence or greedy/search invariant and counts teaching operations rather than measuring animation time.
The four reference languages show the core operations under the same bounded input assumptions. Full tables preserve predecessor information for reconstruction; a table-only reference returns those states for the caller to backtrack. Backtracking references include N-Queens, subsets, permutations and a budgeted 9×9 Sudoku solver.
Use for constrained search and explicit enumeration such as N-Queens, Sudoku, subsets and permutations.
Pruning does not remove worst-case exponential work. A search budget ending does not prove unsatisfiability.
Check the state definition, cost model and boundary conditions below.
MAKE IT STICK
Progress saves on this device and merges with your account after sign-in.
0 / 5000 · Saved on this device; synced when signed in.