Professional Documents
Culture Documents
Backtracking & Branch and Bound
Backtracking & Branch and Bound
&
Branch and Bound
Backtracking
Suppose you have to make a series of
decisions, among various choices, where
You dont have enough information to know
what to choose
Each decision leads to a new set of choices
Some sequence of choices (possibly more
than one) may be a solution to your problem
Backtracking Algorithm
Based on depth-first recursive search
Approach
1. Tests whether solution has been found
2. If found solution, return it
3. Else for each choice that can be made
a) Make that choice
b) Recur
c) If recursion returns a solution, return it
Backtracking
Performs a depth-first traversal of a
tree
Continues until it reaches a node that
is non-viable or non-promising
Prunes the sub tree rooted at this
node and continues the depth-first
traversal of the tree
Backtracking
Backtracking is a technique used to solve problems
with a large search space, by systematically trying
and eliminating possibilities.
A standard example of backtracking would be
going through a maze.
At some point in a maze, you might have two options of
which direction to go:
Portion B
n
o
i
t
Portion A
c
n
Ju
Backtracking
strategy would
At
n
o
i
t
Portion B
Portion A
One
Backtracking
Clearly, at a single
junction you could have
even more than 2 choices.
The backtracking strategy
says to try each choice,
one after the other,
if you ever get stuck,
"backtrack" to the
junction and try the next
choice.
Ju
on
i
t
nc
C
B
Q
Q
Q
Q
Continue
Animated Example:
http://www.hbmeyer.de/bac
ktrack/achtdamen/eight.ht
m#up
}
}
Backtracking
Backtracking prunes
entire sub trees if
their root node is
not a viable solution
The algorithm will
backtrack up the
tree to search for
other possible
solutions
Efficiency of Backtracking
This given a significant advantage
over an exhaustive search of the tree
for the average problem
Worst case: Algorithm tries every
path, traversing the entire search
space as in an exhaustive search
Example:
The Traveling Salesman Problem
Branch and bound can be used to solve the TSP
using a priority queue as an auxiliary data structure
An example is the problem with a directed graph
given by this adjacency matrix:
Bound