Unit V Backtracking and Branch & Bound
Unit V Backtracking and Branch & Bound
For example, for A={1, 2, 5, 6, 8} and d=9, there are two solutions:
{1, 2, 6} and{1, 8}. Some instances of this problem may have no solutions.
The state-space tree for this problem is a binary tree constructed as follows:
• Each node on the ith level of this tree, 0≤i≤n represents all the subsets of n items that
include a particular selection made from the first i ordered items.
• A branch going to the left indicates the inclusion of the next item, and a branch going to
the right indicates its exclusion.
• Record the total weight w and the total value v of this selection in the node, along with
some upper bound ub on the value of any subset that can be obtained by adding zero or
more items to this selection.
• Upper bound is calculated using the formula:
ub = v + (W−w) (vi+1/wi+1)
Where: v= total value of the items included so far,
W-w = Total capacity – total weight of the items already placed
vi+1/wi+1 = value of the item / weight of the item to be included.
W=10 Weight= [ 4 7 5 3] Value = [ 40 42 25 12] ub= 0+(10-0) (40/4) = 100
1:ub= 40+(10-4)(42/7)
ub = 40+6*6=76
3: w=4+7=11 >10
not feasible
4:ub=40+(10-4)(25/5)= 70
5:ub=65+(10-9)(12/3)=69
8:ub=65+(10-9) = 65
Optimal Solution
6:ub=40+(10-4)(12/3) =64
64 < 65 inferior to
optimal solution
2:ub=0+(10-0)(42/7) = 60
60 < 65 inferior to optimal
• Solve the following instance of the knapsack problem by the branch-
and bound algorithm:
Capacity W=16
item 1 2 3 4
Weight 10 7 8 4
Value 100 63 56 12
lb=s/2
Travelling Salesman Problem
• For each city i, 1≤i≤n, find the sums i of the distances from city i to
the two nearest cities; compute the sum s of these n numbers,
divide the result by 2, and, if all the distances are integers, round up
the result to the nearest integer.
lb=[(1+3)+(3+6)+(1+2)+(3+4)+(2+3)]/2=28/2=14
a b c d e
Travelling Salesman Problem
Limitations of Algorithm Power
• Algorithms are very powerful instruments of problem-solving
especially when they are executed by modern computers.
• The power of algorithms is not unlimited, and its limits are the
subject of this chapter.
• Some problems cannot be solved by any algorithm.
• Other problems can be solved algorithmically but not in
polynomial time.
• Even when a problem can be solved in polynomial time by some
algorithms, there are usually lower bounds on their time efficiency.
• Lower Bounds are estimates on a minimum amount of work needed
to solve a problem
Decision Trees
• Performance (time efficiency) of some algorithms can be studied with a
device called a decision tree.
Eg. Algorithms which work by comparing items of their inputs such as sorting
and searching.
Efficiency of an algorithm using Decision Tree
• The algorithm’s work on a particular input of size n can be traced by a path from
the root to a leaf in its decision tree, and the number of comparisons made by the
algorithm on such a run is equal to the length of this path.
• Hence, the number of comparisons in the worst case is equal to the height of the
algorithm’s decision tree.
• A tree with a given number of leaves, which is dictated by the number of possible
outcomes, has to be tall enough to have that many leaves. Specifically, it is not
difficult to prove that for any binary tree with l leaves and height h, is h≥log2l.
• A binary tree of height h with the largest number of leaves has all its leaves on the
last level. Hence, the largest number of leaves in such a tree is 2h in other words,
2h≥l,
• It is a lower bound on the heights of binary decision trees and hence the worst-case
number of comparisons made by any comparison-based algorithm for the problem
in question. Such a bound is called the information theoretic lower bound .
Decision Trees for Sorting
Eg. Hamiltonian circuit problem, the partition problem, decision versions of the
traveling salesman, the knapsack, graph coloring, and many hundreds of other
difficult combinatorial optimization problems.
NP-complete Problem
NP-complete problem is a problem in NP that is as difficult as any other problem in this class.
A decision problem D is said to be polynomially reducible to a decision problem D2, if there
exists a function t that transforms instances of D1 to instances of D2 such that:
1. t maps all yes instances of D1 to yes instances of D2 and all no instances of D1 to no
instances of D2
2. t is computable by a polynomial time algorithm
This definition immediately implies that if a problem D1 is polynomially reducible to some
problem D2 that can be solved in polynomial time, then problem D1 can also be solved in
polynomial time.
The optimal solution, as can be easily checked by exhaustive search, is the tour
s∗:a−b−d−c−a of length 8. Thus, the accuracy ratio of this approximation is: