Back Trcacking
Back Trcacking
General Concepts
Algorithm strategy
Approach to solving a problem
May combine several approaches
Algorithm structure
Iterative execute action in loop
Recursive reapply action to subproblem(s)
Problem type
Satisfying find any satisfactory solution
Optimization find best solutions (vs. cost metric)
A short list of categories
Return failure
Backtracking
Start
Success!
Success!
Failure
Problem space consists of states (nodes) and actions
(paths that lead to new states). When in a node can
can only see paths to connected nodes
2-color
3-color
Hamiltonian Circuit
(use alphabet order to
a
break the ties)
c d
b e
Coloring a map
8 Queens
Knight's Tour
Knapsack problem / Exhaustive Search
Filling a knapsack. Given a choice of items with various
weights and a limited carrying capacity find the optimal
load out. 50 lb. knapsack. items are 1 40 lb, 1 32 lb. 2
22 lbs, 1 15 lb, 1 5 lb. A greedy algorithm would choose
the 40 lb item first. Then the 5 lb. Load out = 45lb.
Exhaustive search 22 + 22 + 5 = 49.
Branch and Bound
Branch and Bound ( B& B)
An enhancement of backtracking
Similarity
– A state space tree is used to solve a problem.
Difference
– The branch-and-bound algorithm does not
limit us to any particular way of traversing
the tree.
– Used only for optimization problems (since
the backtracking algorithm requires the using
of DFS traversal and is used for non-
optimization problems.
The idea:
Set up a bounding function, which is used to compute a
bound (for the value of the objective function) at a node
on a state-space tree and determine if it is promising
Promising (if the bound is better than the value of the
best solution so far): expand beyond the node.
Nonpromising (if the bound is no better than the value
of the best solution so far): not expand beyond the node
(pruning the state-space tree).