2. Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well
Available for study sessions
Science and Engineering Hall
GWU
Algorithms Graph Traversal Techniques, Branch & Bound 2
LOGISTICS
4. Knowing that an object exists within a certain
distance from us, in an infinite maze, how can we
find it?
Algorithms Graph Traversal Techniques, Branch & Bound 4
INFINITE MAZE
5. 1. Select an unvisited node s, visit it, have it be the
root in a BFS tree being formed. Its level is called
the current level.
2. From each node x in the current level, in the order
in which the level nodes were visited, visit all the
unvisited neighbors of x. The newly visited nodes
from this level form a new level that becomes the
next current level.
3. Repeat the previous step until no more nodes can
be visited.
4. If there are still unvisited nodes, repeat from Step
1.
Algorithms Graph Traversal Techniques, Branch & Bound 5
BREADTH FIRST SEARCH (BFS)
7. Observations: The first node visited in each level is
the first node from which to proceed to visit new
nodes.
This suggests that a queue is the proper data
structure to remember the order of the steps.
Algorithms Graph Traversal Techniques, Branch & Bound 7
BFS IMPLEMENTATION
8. Procedure BFS(input: graph G)
Queue Q; Integer s, x
while (G has an unvisited node) do
s := an unvisited node
visit(s)
Enqueue(s,Q)
While (Q is not empty) do
x := Dequeue(Q)
For (unvisited neighbor y of x) do
visit(y)
Enqueue(y,Q)
Algorithms Graph Traversal Techniques, Branch & Bound 8
BFS PSEUDOCODE
9. Robotics
Optimization problems using Branch and Bound
Algorithms Graph Traversal Techniques, Branch & Bound 9
BFS APPLICATIONS
12. A systematic method for solving optimization problems
A general optimization technique that applies where the
greedy method and dynamic programming fail.
Much slower – often leads to exponential time
complexities in the worst case. If applied carefully, can
lead to algorithms that run reasonably fast on average.
General idea of B&B is a BFS-like search for the optimal
solution, but not all nodes get expanded.
Carefully selected criterion determines which node to expand and
when
Another criterion tells the algorithm when an optimal solution has
been found.
Algorithms Graph Traversal Techniques, Branch & Bound 12
BRANCH AND BOUND
13. Given jobs, resources, and cost matrix (cost if resource i
does job j), how to assign jobs to resources, such that
each job is done by a different resource, and the overall
cost is minimum?
What is the right D&C strategy?
What is the right BFS strategy?
Algorithms Graph Traversal Techniques, Branch & Bound 13
B&B FOR JOB ASSIGNMENT
J1 J2 J3 J4 J5
R1 2 4 5 3 11
R2 3 5 6 4 8
R3 4 3 5 7 9
R4 3 4 3 8 12
R5 4 2 6 4 9
14. What is the lower bound?
[In other words, how much will it cost at
minimum to do the job assignment?]
Each job must be done – so if we add minimum cost
per job, then that must be minimum cost
Each person must do a job – so if we add minimum
cost per resource, then that must be minimum cost
Taking the maximum of these two minimums, is a
good “lower bound”.
Algorithms Graph Traversal Techniques, Branch & Bound 14
LOWER BOUND
15. Any random assignment can be an upper bound
Or, we can use a greedy algorithm for upper bound.
In the context of a minimization problem, upper
bound means: “Here is a solution that I have already
found. We are not interested in solutions that are
more expensive than this.” So, in other words, this
solution now defines the highest cost (the upper
bound on cost) that we are willing to pay.
If we find an even better solution, then we will
decrease our upper bound.
Algorithms Graph Traversal Techniques, Branch & Bound 15
UPPER BOUND
16. Assigning a job to a resource can be a node in the
BFS tree
We need to think about the solution space as a tree,
and define what a node in the tree means with
respect to our problem (job assignment)
Algorithms Graph Traversal Techniques, Branch & Bound 16
BRANCHING
17. B&B is a general algorithm for finding optimal
solutions of various optimization problems,
especially in discrete and combinatorial
optimization.
2 main steps
Branching
Bounding
(If bounding allows, then) Node Elimination
Algorithms Graph Traversal Techniques, Branch & Bound 17
MORE.. (FROM WIKIPEDIA)
18. We can consider a maximization problem just as
easily in B&B as well.
In case of a maximization problem, the “lower
bound” comes from a known solution. The “upper
bound” comes from a theoretical/analytical solution
that typically relaxes some constraint.
Lower bound signifies: A solution we already know exists
Upper bound signifies: Maximum value we could obtain, even if
some constraints were relaxed.
An example of a maximization problem is a 0/1
knapsack problem.
Algorithms Graph Traversal Techniques, Branch & Bound 18
B&B FOR MAXIMIZATION PROBLEMS
19. Given a set of items, each with a weight and a value,
determine which items to include in a collection so
that the total weight is less than a given limit and
the total value is as large as possible.
Different from fractional knapsack, can only take or
not take an item.
No easy solution – greedy solution may not be
optimal.
Algorithms Graph Traversal Techniques, Branch & Bound 19
0/1 KNAPSACK PROBLEM
21. Given a complete graph with n vertices, the
salesperson wishes to make a tour, visiting each city
exactly once and finishing at the city he starts from.
Cost of going from city i to city j = c(i,j).
Algorithms Graph Traversal Techniques, Branch & Bound 21
TRAVELING SALESPERSON PROBLEM (TSP)
22. Input: n jobs, n employees, and an n x n matrix A
where Aij be the cost if person i performs job j.
Problem: Find a one-to-one matching of the n
employees to the n jobs so that the total cost is
minimized.
Formally, find a permutation f such that C(f), where
C(f)=A1f(1) + A2f(2) + ... + Anf(n) is minimized.
Algorithms Graph Traversal Techniques, Branch & Bound 22
JOB ASSIGNMENT PROBLEM
23. Do a Breadth First Search
Evaluate each node for upper and lower bounds
Branch into the “best” node
Terminate if solution meets performance parameters
Algorithms Graph Traversal Techniques, Branch & Bound 23
BRANCH AND BOUND TEMPLATE
24. Branch and Bound depends upon being able to
“bound” each node in the search tree, so that we can
evaluate whether or not to expand it.
Lower bound and upper bound depend on the
problem
Algorithms Graph Traversal Techniques, Branch & Bound 24
BRANCH AND BOUND TEMPLATE (CONT.)
25. Using a mixture of upper and lower bounds, we can
find when might be a right time to terminate the
search.
Algorithms Graph Traversal Techniques, Branch & Bound 25
TERMINATION CRITERIA
26. B&B is an interesting technique that uses BFS and
bounding to eliminate the nodes in the search tree.
Can solve problems that are intrinsically harder.
Time complexity may not be polynomial, but may be
practical.
We can return an approximate, usable solution with
some bound on performance.
Developing interesting bounds depends upon the
problem and uses problem specific insights.
Algorithms Graph Traversal Techniques, Branch & Bound 26
SUMMARY