Skip to main content

Backtracking

Learn Backtracking (Algorithms, Programming Fundamentals) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Backtracking is a technique for solving problems by trying out possible options one at a time, and undoing (backtracking) a choice as soon as it is discovered to be wrong, then trying the next option. Think of it as exploring a maze: you walk forward, and if you hit a dead end, you step back to the last junction and try a different path - instead of restarting from scratch. It is commonly used for: • Generating all subsets/permutations • The N-Queens puzzle • Sudoku solvers • Maze solving

More lessons in Algorithms