In backtracking, i.e. the algorithm used for solving the n-queens problem, there are basically two ways to do the recursive call:
- copy the parent board to make a child board, modify the child board by placing a new queen, then do the recursive call on the child board.
- modify the board directly, do the recursive call, then undo the modification.
The second is preferred since it avoids the costly copy.
This choice is also present in other algorithms, like minimax on games.
Is there a name for pattern 2 as opposed to pattern 1?
In Constraint Programming and SAT-Solving (where your n-queens example usually comes from) i would argue, that these concepts are described as:
See for example:
Excerpt of the former:
Both have their pros and cons, analyzed in the references.
Keep in mind, that the trail is usually not only about storing your decisions (board placements), but also propagations happened (this placement leads to these now impossible placements due to alldifferent propagation: these effects must be reverted as well!). For an overview of the implementation of such, see: MiniCP