Skip to main content

Proofs: Backtracking

Backtracking is an exact method: it promises to find every solution, or the best one. That promise depends on the pruning being safe, that is, never discarding a branch that contains what we are looking for. This page proves when that is the case.


Backtracking finds every solution​

Claim. The "all solutions" scheme of backtracking processes every solution of the tree of states, provided that the feasibility test only rejects partial solutions that cannot be completed into a solution.

Proof. Without pruning, the recursion visits every node of the tree: by induction on the height of a subtree, a call on its root makes one recursive call per child, and each child call visits its whole subtree. With pruning, a child is skipped only if the test rejects it, and by hypothesis then no solution lies in its subtree. So every node that is an ancestor of a solution is visited, and in particular every solution is reached. ■\blacksquare

The "first solution" scheme visits the same nodes in the same order until the first solution, and stops there. If the tree has no solution, it explores everything that is not pruned, so it correctly reports that there is none.

Termination. If every branch of the tree is finite (every path from the root has a bounded length, for example nn decisions), the search terminates. This is not automatic in problems where states can repeat, such as sliding puzzles: there, repeated states must be detected, or the depth limited.


Bound pruning never loses the optimum​

Claim. In a minimization problem, if c^(x)\hat{c}(x) is a lower bound (no solution in the subtree of xx costs less than c^(x)\hat{c}(x)), and UU is the cost of a solution already found, then discarding xx when c^(x)≥U\hat{c}(x) \ge U never removes a solution cheaper than UU.

Proof. Every solution ss in the subtree of xx satisfies cost(s)≥c^(x)≥U\mathrm{cost}(s) \ge \hat{c}(x) \ge U. So none of them is better than the solution we already have. ■\blacksquare

Two consequences:

  • The bound must be a true lower bound. If it can exceed the real cost of the best solution below xx, the argument breaks, and the optimum can be pruned.
  • The simplest bound is the cost accumulated so far when costs are non-negative, as in the task assignment by backtracking: adding more decisions can only increase the cost. Better bounds also estimate the cost still to come.

For maximization everything is mirrored: an upper bound v^(x)\hat{v}(x), and xx is discarded when v^(x)≤\hat{v}(x) \le the best value found.

Saved only in your browser
Was this lesson helpful?
Questions, or something wrong?

Errors, suggestions and public questions open a form on GitHub, visible to everyone.