Browse Curriculum

Backtracking and Constraint Search

Backtracking is search with an undo. You commit to a choice, recurse, and if the choice cannot lead anywhere valid you unwind it and try the next. Described that way it sounds simple; written as recursive code with a mutable state that has to be restored precisely, it is a common source of confusion.

This is the topic where watching execution helps most, because the shape of the algorithm is a tree being walked and pruned. Seeing N-Queens place a queen, hit a conflict several rows later and unwind makes the undo step concrete, and the same structure then reads clearly in subsets, permutations and Sudoku.

6
Interactive lessons
4
Languages (JS, Python, Java, C++)

Backtracking lessons


Continue the DSA curriculum

Backtracking is one of 12 topics in the interactive DSA visualizer curriculum. Once this topic is comfortable, the coding interview pattern library reorganises the same material around the patterns interview questions are built on.

Every other DSA visualizer