Backtracking Algorithms
Try, and step back when you hit a wall. Learn the 3 topics below step by step with interactive visualizations.
The problem of placing N queens on an N×N chessboard so none can attack another. It tries one queen per row, checking column and diagonal conflicts, and backs off to the previous choice when stuck — the classic backtracking pattern.
O(N!)The problem of finding a path from start to goal in a grid maze. It's solved with backtracking: push forward in one direction, and when you hit a wall or dead end, return to the last junction and try another direction.
O(4^(N·M))The puzzle of filling a 9×9 grid so 1–9 appears exactly once in each row, column, and 3×3 box. It's backtracking: try a possible number in an empty cell, and on a contradiction reset it to 0 and try another.
O(9^(empty cells))