Docsity

Branch and Bound Algorithm: Breadth-First Search and Graph Traversal Techniques, Lecture notes of Data Structures and Algorithms

Partial preview of the text

Download Branch and Bound Algorithm: Breadth-First Search and Graph Traversal Techniques and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Analysis and

Design of

Algorithms

BREADTH FIRST

SEARCH, BRANCHING

AND BOUNDING

Instructor

Prof. Amrinder Arora

[email protected]

Please copy TA on emails

Please feel free to call as well

Available for study sessions

Science and Engineering Hall

GWU

LOGISTICS

Textbook

Second Edition

Cognella Academic Publisher

www.cognella.com

ISBN:

978-1-63487-073-

Knowing that an object exists within a certain

distance from us, in an infinite maze, how can

we find it?

INFINITE MAZE

  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.

  1. 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.

  1. Repeat the previous step until no more nodes

can be visited.

  1. If there are still unvisited nodes, repeat from

Step 1.

BREADTH FIRST SEARCH (BFS)

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.

BFS IMPLEMENTATION

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)

BFS PSEUDOCODE

Hamiltonian Cycle

K-clique

K-coloring

OTHER GRAPH PROBLEMS

Algorithms

Analysis

Asymptotic

NP-

Completene

ss

Design

D&C

Greedy

DP

Graph

B&B

Applications

WHERE WE ARE

 Done

 Done

 Starting

today..

 Done

 Done

 Done

 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?

B&B FOR JOB ASSIGNMENT

J1 J2 J3 J4 J

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

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”.

LOWER BOUND

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)

BRANCHING

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

MORE.. (FROM WIKIPEDIA)

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.

0/1 KNAPSACK PROBLEM

3 Items. Knapsack can hold 50 lbs.

 Item 1 weighs 10 lbs, worth 60$

 Item 2 weighs 20 lbs, worth 100$

 Item 3 weighs 30 lbs, worth 120$

Greedy solution: Item 1 + Item 2, worth =

Optimal solution: Item 3 + Item 2, worth =

0/1 KNAPSACK EXAMPLE