All lessons in Software Engineering: Programs, Systems, and Maintainable Software

Backtracking and Search-Space Pruning

Enumerate valid assignments using reversible decisions and sound pruning.

35 minutes · Members lesson · preview

What you will learn

  • Describe a search state, candidate decision, and reversible update.
  • Prune a branch only when no valid completion can remain.
  • Distinguish exhaustive search from optimization with a proven bound.

Three library events need rooms. Some events overlap, and not every room has the required capacity. A greedy assignment can use the only suitable room for an easy event and leave a later event impossible. Backtracking explores a decision, checks its consequences, and reverses it when that branch cannot lead to a valid solution.

The technique is useful when the solution space is manageable or constraints eliminate much of it. Its flexibility does not remove the possibility of exponential work, so define the search space and stopping condition clearly.

Choose another lesson