Branch and Bound
Branch and Bound
CS31005: Algorithms-II
Autumn 2020
IIT Kharagpur
Branch and Bound
An algorithm design technique, primarily for solving hard
optimization problems
Guarantees that the optimal solution will be found
Does not necessarily guarantee worst case polynomial time
complexity
But tries to ensure faster time on most instances
Basic Idea
Model the entire solution space as a tree
Search for a solution in the tree systematically, eliminating parts
of the tree from the search intelligently
Important technique for solving many problems for which
efficient algorithms (worst case polynomial time) are not
known
Optimization Problems
Set of input variables I
Set of output variables O
Values of the output variables define the solution space
Set of constraints C over the variables
Set of feasible solutions S
Set of solutions that satisfy all the constraints
Objective function F: S → R (also called cost function)
Gives a value F(s) for each solution s ∈ S
Optimal solution
A solution s ∈ S for which F(s) is maximum among all s ∈ S
(for a maximization problem) or minimum (for a minimization
problem)
Example
Many problems that you have seen so far
Minimum weight spanning tree, matrix chain multiplication,
longest common subsequence, fractional knapsack problem, ….
All these (that you have seen in Algorithms-1 course) have known
efficient algorithms
Graph Coloring
Input: an undirected graph
Output: a color assigned to each vertex
Constraint: no two adjacent vertices have the same color
Objective function: no of colors used by a feasible solution
Goal: Find a coloring that uses the minimum number of colors
No efficient algorithm known for general graphs
Bin Packing
Input: a set of items X = {x1, x2, ….xn} with volume {v1, v2,
vn} respectively, and set of bins B, each of volume V
Output: an assignment of the items to bins (each item can be
placed in exactly one bin)
Constraint: the total volume of items placed in any bin must be
≤V
Objective function: number of bins used
Goal: find an assignment of items to bins that uses the minimum
number of bins
No efficient algorithm known
Note that a maximization problem can be transformed into a
minimization function (and vice-versa) by just changing the
sign of the objective function
Solution Structure
For many optimization problems, the solution can be
expressed as a n-tuple <x1, x2, ….xn> where each xi is
chosen from some finite set Si
Let size of Si be mi
Then size of the solution space = m1m2m3….mn
Some of these solutions are feasible, some are infeasible
Brute force approach
Search the entire space for feasible solutions
Compute the cost function for each feasible solution found
Choose the one that maximizes/minimizes the objective
function
Problem: Solution space size may be too large
Example: 0-1 Knapsack Problem
Given a set of n items 1, 2, …n with weights w1, w2, …, wn
and values v1, v2, vn respectively , and a knapsack with total
weight capacity W, find the largest subset of items that can
be packed into the knapsack such that the total value
gained is maximized.
Solution format <x1, x2,….,xn>
xi = 1 if item i is chosen in the subset, 0 otherwise
Feasible solution: ∑ xiwi ≤ W
Objective function F: ∑ xivi
Optimal solution: feasible solution with maximum value of ∑
xivi
Solution space size 2n
Example: Travelling Salesman Problem
Given a complete weighted graph G = (V, E), find a
Hamiltonian Cycle with the lowest total weight
Suppose that the vertices are numbered 1, 2, …,|V|= n
Solution format <x1, x2,….,xn>
xi ∈ {1, 2, …,n} gives the i-th vertex visited in the cycle
Feasible solution: xi ≠ xj for any i ≠ j
Objective function F: ∑ 1 ≤ i < n w(xi, xi+1) + w(xn, x1),
where w(i, j) is the weight of edge (i, j)
Optimal solution: feasible solution with minimum value
of objective function
Solution space size (n-1)!
State Space Tree
Represent the solution space as a tree
Each edge represents a choice of one xi
Level 0 to Level 1 edges show choice of x1
Level 1 to Level 2 edges show choice of x2