COP 3503 – Computer Science II
–
CLASS NOTES

DAY #9
Backtracking Algorithms
Backtracking algorithms use recursion to try all possible solutions and pick the
optimal solution from the set of all solutions.
This is a common strategy employed
in AI games, parsers, etc.
Since trying all possible solutions is essentially an
exhaustive searching technique there must be a technique which will allow a
backtracking algorithm to “know” that some solution paths are not optimal and
therefore need not be explored.
This technique is known as
search tree pruning
and we will examine it later.
Many problems can be viewed in terms of abstract graphs.
For example, the nodes
in a graph can represent the positions in a chess game and the edges represent the
legal moves.
Often the original problem translates to searching for a specific node,
path, or pattern in the associated graph.
If the graph contains a large number of
nodes, and particularly if it is infinite, it may be wasteful or infeasible to explicitly
build it in memory before applying a search technique to the graph.
In such cases
an
implicit graph
is required.
An implicit graph (recall that a tree is just a special
case of a graph) is one for which a description of its nodes and edges is available,
so that only the relevant parts of the graph are constructed as the search progresses.
Computing time is reduced whenever the search succeeds before the entire graph
has been constructed.
A savings in terms of memory is also achieved with implict
graphs and can be further enhanced whenever nodes that have been previously
searched can be discarded thereby making room for nodes to be subsequently
explored (this is not always possible however).
If the graph is infinite, then the
implicit graph technique offers the only hope of exploring all of the graph.
In its basic form, backtracking resembles a depthfirst search in a digraph (directed
graph).
The digraph concerned is typically a tree (or at least it contains no cycles).
The digraph is assumed to be implicit regardless of its structure.
The aim of the
search is to find solutions to the problem represented by the digraph.
This is done
by building partial solutions as the search proceeds; such partial solutions limit the
regions in which a complete solution may be found.
Generally speaking, when a
search begins, nothing is known about the solutions to the problem.
Each move
along an edge of the implicit graph corresponds to adding a new element to a
partial solution, i.e., it narrows down the remaining possibilities for a complete
solution.
The search is successful if, proceeding in this way, a solution can be
completely defined.
In this case the algorithm may stop (if there only one solution
to the problem is required) or continue looking for alternative solutions (if you
would like to see all of the solutions).
On the other hand, the search is
unsuccessful if at some stage the partial solution constructed so far cannot be
completed.
In this case, the search
backsup
(exactly like a depthfirst tree search),
Day 9 
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.