CSE408
Vertex Cover and Bin
Packing
The Vertex Cover Problem
• Problem statement
– a vertex cover of an undirected graph is a set of
vertices V’ V such that if (u,v) G then either
u V’ or v V’ or both
– the vertex cover problem is the find the smallest
subset that covers an undirected graph
Example
Polling
• What is the minimum vertex cover?
a) 0 b) 1 c) 2 d) 4
Polling
• What is the minimum vertex cover?
Set Cover Problem
• Given a set of elements {1,2,...,n} (universe)
and a collection S of m sets whose union
equals the universe, the set cover problem is
to identify the smallest sub-collection of S
whose union equals the universe.
How it works
• How the algorithm works
– C contains the cover which is initialized to
– E’ is a copy of the edges of the graph
– every time an edge (u,v) is selected from E’, it is added
to the cover and edge incident on u or v is removed
from E’; the algorithm stops when E’ is
The Set-covering Problem
• Problem statement
– given a finite set X and a family F of subsets where
every element of X is contained in one of the subsets
of F, then S covers X provided X S
SF
– the problem is to find the minimum size subset C that
covers all of X X S
SC
• An example
– {S1,S4,S5,S6} is a cover
– {S3,S4,S5} is a minimum
cover
• This problem generalizes
the vertex-cover problem
Set Cover Problem
A Greedy Algorithm
• How the algorithm works
– U is the set of elements not covered yet
– select S each time to remove the most elements from
U.
Polling
U = {1,2,3,4,5,6}
S = {S1,S2,S3,S4}
S1 = {6,1,3}, Cost(S1) = 8
S2 = {2,5,4}, Cost(S2) = 7
S3 = {1,4,3,6}, Cost(S3) = 5
• What is the minimum cost of set cover and what
is that set?
Bin-Packing
The Bin-Packing Problem:
You have items of different sizes or weights:
e.g: 1 (30kg) 2 (25kg) 3 (10kg) 4 (20kg) 5 (15kg)
1 2
3 4 5
And you have several `bins’ with a max capacity, say 50kg.
bin1 bin2 bin3 bin4 etc …
Find a way to pack them into the smallest number of bins. This is, in general, a hard
problem.
Bin-Packing
One packing
1 (30kg) 2 (25kg) 3 (10kg) 4 (20kg) 5 (15kg)
1 2
3 4 5
And you have several `bins’ with a max capacity, say 50kg.
5 4
1 2
3
bin1 bin2 bin3 bin4 etc …
bin1 and bin2 have 45kg -- so the 10kg item 3 needs a new bin
Bin-Packing
Another packing
1 (30kg) 2 (25kg) 3 (10kg) 4 (20kg) 5 (15kg)
1 2
3 4 5
And you have several `bins’ with a max capacity, say 50kg.
4 5
3
1 2
bin1 bin2 bin3 bin4 etc …
by putting items 1 and 4 together, we can now fit the rest in one bin
Bin-Packing
• Single-class algorithms
– If the item fits into one of the currently open bins, then put it in one of these bins;
– Otherwise, open a new bin and put the new item in it.
• Next Fit (NF) always keeps a single open bin. When the new item does not fit
into it, it closes the current bin and opens a new bin.
• Next-k-Fit (NkF) is a variant of Next-Fit, but instead of keeping only one bin
open, the algorithm keeps the last k bins open and chooses the first bin in which
the item fits.
• First-Fit (FF) keeps all bins open, in the order in which they were opened. It
attempts to place each new item into the first bin in which it fits.
• Best-Fit (BF), too, keeps all bins open, but attempts to place each new item into
the bin with the maximum load in which it fits.
Bin-Packing
• Single-class algorithms
– If the item fits into one of the currently open bins, then put it in one of these bins;
– Otherwise, open a new bin and put the new item in it.
• Next Fit (NF) always keeps a single open bin. When the new item does not fit
into it, it closes the current bin and opens a new bin.
• Next-k-Fit (NkF) is a variant of Next-Fit, but instead of keeping only one bin
open, the algorithm keeps the last k bins open and chooses the first bin in which
the item fits.
• First-Fit (FF) keeps all bins open, in the order in which they were opened. It
attempts to place each new item into the first bin in which it fits.
• Best-Fit (BF), too, keeps all bins open but attempts to place each new item into
the bin with the maximum load in which it fits.
• Multiplicative approximation
• Ordering the input list by descending size;
• Put the item in the bins.
Polling
Let U = {1,2,3,8,9,15}
And S1= {8,1,2,9}, Cost = 5
S2 = {15,1,3,8}, Cost = 6
S3= {9,8,2,15}, Cost = 4
Find the minimum cost set cover.
Polling
Choose the packing that results from the use of the first fit (FF) bin-packing
algorithm to pack the following weights into bins that can hold no more than 9
lbs.
4 lbs, 5 lbs, 3 lbs, 2 lbs, 7 lbs, 6 lbs, 4 lbs, 2 lbs
1. a 2. b 3. c 4. Another packing