8. What is backtracking? Give an example.
MediumRecursion & backtracking
Technical
Show model answer
Backtracking builds a solution step by step and abandons (prunes) a partial solution as soon as it cannot lead to a valid answer, then undoes the last choice and tries the next. It is a depth-first search over the space of choices.
Examples: generating subsets and permutations, N-Queens, Sudoku, and combination sums. The program prints all binary strings of length 3.