Backtracking Algorithm

(Redirected from backtracking)
Jump to navigation Jump to search

A Backtracking Algorithm is a search algorithm that incrementally builds solution candidates, and abandons each partial candidate [math]\displaystyle{ c }[/math] ("backtracks") as soon as it determines that [math]\displaystyle{ c }[/math] cannot possibly be completed to a valid solution.



  • (Wkipedia, 2009) ⇒
    • Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate [math]\displaystyle{ c }[/math] ("backtracks") as soon as it determines that [math]\displaystyle{ c }[/math] cannot possibly be completed to a valid solution.
    • The classic textbook example of the use of backtracking is the eight queens puzzle, that asks for all arrangements of eight queens on a standard chessboard so that no queen attacks any other. In the common backtracking approach, the partial candidates are arrangements of [math]\displaystyle{ k }[/math] queens in the first [math]\displaystyle{ k }[/math] rows of the board, all in different rows and columns. Any partial solution that contains two mutually attacking queens can be abandoned, since it cannot possibly be completed to a valid solution.
    • Backtracking can be applied only for problems which admit the concept of a "partial candidate solution" and a relatively quick test of whether it can possibly be completed to a valid solution. It is useless, for example, for locating a given value in an unordered table. When it is applicable, however, backtracking is often much faster than brute force enumeration of all complete candidates, since it can eliminate a large number of candidates with a single test.
    • Backtracking is an important tool for solving constraint satisfaction problems, such as crosswords, verbal arithmetic, and many other puzzles. It is often the most convenient (if not the most efficient) technique for parsing, for the knapsack problem and other combinatorial optimization problems. It is also the basis of the so-called logic programming languages such as Icon, Planner and Prolog. Backtracking is also utilized in the (diff) difference engine for the MediaWiki software.
    • Backtracking depends on user-given “black box procedures" that define the problem to be solved, the nature of the partial candidates, and how they are extended into complete candidates. It is therefore a metaheuristic rather than a specific algorithm --- although, unlike many other meta-heuristics, it is guaranteed to find all solutions to a finite problem in a bounded amount of time.


  • (Jones, 2008) ⇒ M. Tim Jones. (2008). “Artificial Intelligence: A Systems Approach.” Jones & Bartlett. ISBN:0763773379
    • The backtracking algorithm operates with a simple uninformed search algorithm, such as depth-first search. At each node, a variables is instantiated with a value and the constraint violations are checked. If the values are legal, search is permitted to continue, otherwise, the current branch is abandoned and the next node from the OPEN list is evaluated.



  • Douglas C. Schmidt, and Larry E. Druffel. (1976). “A Fast Backtracking Algorithm to Test Directed Graphs for Isomorphism Using Distance Matrices.” In: Journal of the ACM, 23(3). doi:10.1145/321958.321963