Algorithms and Data Structures · Middle · Question 49 of 75
What is backtracking?
- 1Running an algorithm backwards from the answer to the input
- ✓Correct answer: Building a solution step by step and undoing dead-end choices
- 3Undoing the last database transaction when an error occurs
Explanation
It's a DFS over choices: add a choice, recurse, remove it. Pruning (stopping early when the partial solution can't work) is what keeps it practical. Classic problems: permutations, N-Queens, Sudoku.