Coping with NP Hardness
Introduction
Duties
Base the grade on a final exam with an open material.
No obligatory homework, but strongly recommended.
Example โ The Traveling Salesman Problem (TSP)
We have ๐ cities โ {1, โฆ , ๐}
โ๐, ๐ โ {1, โฆ , ๐} thereโs a distance ๐๐,๐
๐โ1
๐ค(๐) = โ ๐๐๐,๐๐+1
๐=1
TSP
Input: ๐๐,๐ , B
Question: Is there a tour ๐ of length (๐) โค ๐ต ?
๐๐๐๐๐๐ข๐๐ :
Input: ๐๐,๐
Question: Find ๐ตโ (shortest path โ with length ๐ค(๐ โ ))
๐๐๐๐๐๐ก :
Input: ๐๐,๐
Question: Find ๐ โ
๐๐๐๐๐๐ :
Input: ๐๐,๐ ,B
Question: Find all the tours ๐ s.t. ๐ค(๐) โค ๐ต
๐๐ด (๐ฅ) = the time it will take the algorithm to run
๐๐ด (๐) = max{๐๐ด (๐ฅ)|๐๐๐๐๐กโ(๐ฅ) = ๐}
P = consists of all the problems that have a poly-time algorithm.
NP = consists of all the problems that have a polynomial time verifier (or have a nondeterministic polynomial time algorithm).
Formally: ๐๐ =
{๐๐๐๐๐๐๐๐ ๐|๐โ๐๐๐ ๐๐ ๐ ๐๐๐๐ฆ โ ๐ก๐๐๐ ๐๐๐ โ ๐๐๐ก๐๐๐๐๐๐๐ ๐ก๐๐ ๐๐๐๐๐๐๐กโ๐ ๐๐๐ ๐๐๐๐๐๐๐๐ ๐}
EXP = The class of problems that have an exp-time algorithm.
NP Completenes
A problem ๐ Is NP-Complete if:
(1) ๐ โ ๐๐
(2) โ๐ โฒ โ ๐๐. ๐โฒ โ ๐ (there is a poly-time transformation from ๐โฒ to ๐)
TODO: Draw reductions from NP to NP-Complete problems
NP
P
๐
๐โฒโฒ
๐โฒ
Scheme for proving a problem is NP-Complete
To prove that a problem ๐ is NP-Complete:
(1) Show that ๐ โ ๐๐
(2) Show that ๐โฒ โ ๐ for some ๐โฒ that is already known to be NP-Complete.
Example โ Partition problem
Input: Integers โ ๐ถ = {๐1 , โฆ , ๐๐ }
Questions: Is there a subset ๐ โ {1, โฆ , ๐} s.t. โ๐โ๐ ๐๐ =
๐
๐ต
2
๐ต = โ ๐๐
๐=1
Turing Reduction
๐1 โ ๐ ๐2 (๐1 is turing reducible to ๐2 )
If given a procedure P that solves ๐2 instances in constant time , It is possible to device a
polynomial time algorithm for ๐1 .
An obvious observation would be that:
๐๐๐ โ ๐ ๐๐๐๐๐๐ข๐๐ โ ๐ ๐๐๐๐๐๐ก
But what about:
๐๐๐๐๐๐ข๐๐ โ ๐ ๐๐๐
A detailed explanation -
Given: Procedure P that gets ๐๐,๐ , ๐ต and returns T/N
Devise: Algorithm for ๐๐๐๐๐๐ข๐๐
Input: ๐๐,๐
Find: ๐ตโ
We can easily do it by a binary search for ๐ตโ in the range [1, ๐ โ max ๐๐,๐ ]
The sums of all weights is not always polynomial:
๐๐,๐ = 2100 , ๐ = 100
Each number is only a 100 bits, but their sum is a number exponential in the size of the input.
What about:
๐๐๐๐๐๐ก โ ๐ ๐๐๐๐๐๐ข๐๐ ?
K-largest subses (KLS)
Input: ๐ถ = {๐1 , โฆ , ๐๐ }, ๐พ, ๐ต (๐1 , โฆ , ๐๐ โ โค)
C has 2๐ subsets ๐๐ โ ๐ถ
๐ก๐ = โ ๐๐
๐๐ โ๐๐
๐1 , ๐2 , โฆ , ๐2๐
๐ก1 โฅ ๐ก2 โฅ โฏ โฅ ๐ก2๐
Question: Are there at least k subsets ๐๐ of ๐ถ of size ๐ก๐ โฅ ๐ต?
Claim: Partition โ ๐ KLS
Proof: Assume given a procedure ๐(๐ถ, ๐พ, ๐ต) โ ๐/๐ for ๐พ๐ฟ๐.
We need a procedure ๐(๐ถ, ๐ต) returning an index ๐ s.t. ๐ก๐ โฅ ๐ต > ๐ก๐+1
Answer: We should look at the range [1,2๐ ] and perform a binary search on it. By that we would
find exactly the B that is the threshold.
Now we should use the procedure Q to produce and algorithm for partition.
๐ถ = {๐1 , โฆ , ๐๐ }
1
1. ๐ต โ 2 โ ๐๐
2. ๐1 โ ๐(๐ถ, ๐ต)
3. ๐2 โ ๐(๐ถ, ๐ต + 1)
4. If ๐1 = ๐2 then return No. Else return Yes.
Home Exercise: Prove the reduction is correct.
A harder home exercise: Give a polynomial transformation from ๐๐๐๐ก๐๐ก๐๐๐ โ ๐พ๐ฟ๐.
A problem is self-reducible if there is a Turing reduction from its optimization version to its
decision version.
An example: ๐๐๐๐๐ก โ ๐ ๐๐๐ โ ๐๐๐ is self reducible.
Another example: Clique is self-reducible.
Lets first define Cliqueโฆ
๐ถ๐๐๐๐ข๐:
Input: Graph ๐บ,integer ๐พ
Question: Does ๐บ contain a Clique of size โฅ ๐?
A Clique is a complete sub-graph.
Proof: need to show ๐ถ๐ฟ๐๐๐๐ก โ ๐ ๐ถ๐ฟ๐๐๐๐
Or in other words โ given a procedure ๐(๐บ, ๐) which answers whether ๐ถ๐ฟ๐๐๐๐ has a Clique of
size ๐.
We need to devise an algorithm to find the biggest Clique in graph ๐บ.
Algorithm:
1) Find ๐ โ which is the size of the largest Clique in ๐บ by applying ๐(๐บ, ๐) for0020๐ = 1, โฆ
2) For every ๐ฃ โ ๐บ do:
a. Set ๐บ โฒ โ ๐บ \{๐ฃ} (erase ๐ฃ and all its edges)
b. ๐ โ ๐(๐บ โฒ , ๐ โ)
c. If ๐ = ๐ then ๐บ โ ๐บโฒ else set ๐บ โ ๐บ({๐ฃ} โช ๐(๐ฃ))
Home exercise 3: Show that dominating set is self reducible.
๐ โ ๐ in graph ๐บ is a dominating set if โ๐ฅ โ ๐\๐ has a neighbor in ๐.
๐ท๐๐๐๐๐ :
Input: ๐บ, ๐
Question: Does ๐บ have a dominating set of size โค ๐.
๐ท๐๐๐๐๐ก :
Input: ๐บ
Question: Find the smallest dominating set.
Pseudo-Polynomial Algorithms
Knapsack Problem
Input: Item types 1, โฆ , ๐. Each item has a size ๐๐ and cost ๐ถ๐ .
Also given a knapsack of size ๐พ. Profit target ๐ต.
Question: Are there integers {๐ฅ1 , โฆ , ๐ฅ๐ } s.t. โ๐๐=1 ๐ฅ๐ ๐๐ โค ๐พ and the profit is larger than B
(โ๐๐=1 ๐ฅ๐ ๐ถ๐ โฅ ๐ต)
Uniform Knapsack
A variant in which K=B (๐๐ = ๐ถ๐ )
Question: โ๐ฅฬ
, โฆ , ๐ฅฬ
๐ s.t. โ ๐ฅ๐ ๐ถ๐ = ๐.
0-1 Knapsack
Same except ๐ฅ๐ โ {0,1}
Algorithm for Uniform Knapsack
Stage A
Build a DAG (Directed Acyclic Graph) on ๐ = {0, โฆ , ๐}
๐ธ = {โฉ๐ด, ๐ตโช|1 โค ๐ด < ๐ต โค ๐, โ๐. ๐ด + ๐ถ๐ = ๐ต}
Example:
๐=8
0
1
2
3
4
5
6
7
Stage B
Check reachibility from 0 to ๐ in the DAG.
Home exercise 4: Prove that ๐ ks reachable from 0 โ โ ๐พ(๐ถฬ
, ๐พ) = ๐ฆ.
max(๐ผ) = largest number in the input ๐ผ.
A is a pseudo-polynomial time algorithm for a problem ๐ if its complexity is bounded by a
polynomial in both length of the input and max(๐ผ).
---------- End of lesson 1
Pseudo Polynomial Algorithms
Instance ๐ผ composed of numbers
๐๐๐๐๐กโ(๐ผ)
max(๐ผ) =largest number in ๐ผ.
๐ด is pseudo-polynomial if โpolynomial ๐ ๐ . ๐ก. โ๐ผ, ๐๐ด (๐ผ) โค ๐(๐๐๐๐๐กโ(๐ผ), max(๐ผ))
Strongly NP-Hardness
For problem ๐, denote by ๐๐ (๐ is some polynomial) the problem restricted to instances ๐ผ in
which max(๐ผ) โค ๐(๐๐๐๐๐กโ(๐)).
๐ is strongly NP-Hard if ๐๐ is NP-Hard.
Fact: If ๐ is strongly NP-Hard it does not have a pseudo-polynomial time algorithm (unless
P=NP).
Exercise 1: Prove.
0-1 knapsack
Input: ๐ถ = {๐1 , โฆ , ๐๐ }, ๐
Question: Is there a subset ๐ โ {1, โฆ , ๐} ๐ . ๐ก. โ๐โ๐ ๐๐ = ๐?
Dynamic Programming
๐(๐, ๐) = {
1 โ๐ โ {1, โฆ , ๐} ๐ . ๐ก. โ ๐๐ = ๐
0
For 1 โค ๐ โค ๐, 0 โค ๐ โค ๐
๐โ๐
๐๐กโ๐๐๐ค๐๐ ๐
The final answer would be: ๐(๐, ๐).
Process: We start by filling row ๐ = 1.
1 ๐ = 0 โจ ๐ = ๐1
๐(1, ๐) = {
0
๐๐กโ๐๐๐ค๐๐ ๐
Suppose we filled rows till ๐, and now we fill row ๐ + 1:
1 ๐(๐, ๐) โจ ๐(๐, ๐ โ ๐๐+1 )
๐(๐ + 1, ๐) = {
0
๐๐กโ๐๐๐ค๐๐ ๐
Time: ๐(๐๐พ). So itโs pseudo polynomial.
๐ป๐บ๐ท๐๐๐
Input: ๐๐,๐
๐ ๐
The number of possibilities is (๐ โ 1)! โ ๐ = ๐! ~ ( ๐ ) ~2๐(๐ ๐๐๐๐)
We want to do it in ๐(๐(๐) โ 2๐ )
๐ = {2, โฆ , ๐}
๐(๐, ๐) = length of the shortest tour that starts at city 1, visits all visits of ๐ exactly once and
ends at ๐.
Process of filling ๐:
For |๐| = 1: ๐ = {๐}.
๐(๐, ๐) = ๐๐,๐
For |๐| = ๐ + 1:
Letโs define ๐ โฒ to be the vertices between city 1 and ๐.
|๐ โฒ | = ๐.
๐(๐, ๐) = min{๐(๐, ๐ โฒ )|๐ โฒ โ ๐, |๐ โฒ | = ๐, ๐ โ ๐ โฒ}
Final answer: min{๐(๐, ๐) + ๐๐,1 }
๐โ๐
We have 2๐โ1 different subsets times n. And ๐ operations for each cell.
So in conclusion we are talking about 2๐โ1 โ ๐2 .
Exercise 2: Find the shortest TSP path (and not cycle).
TSP Path:
You start at some city ๐1 and travel to a city ๐๐ . Allowing you to start or to end at any city.
Exercise 3: TSP with dependent distances:
Input: ๐๐,๐,๐ - the cost/distance for going from ๐ to ๐ if the city you visited be fore was ๐.
Recursion
3SAT
Input: ๐ = โ๐
๐=1 ๐๐
๐
๐
๐๐ = (๐ข1 โจ ๐ข2 โจ ๐ข3๐ ), ๐ข๐ โ {๐ฅ๐ , ๐ฅฬ
๐ }
Question: Does ๐ have a satisfying truth assignment ๐: {๐ฅ1 , โฆ , ๐ฅ๐ } โ {๐, ๐น} ๐ . ๐ก. ๐(๐ฅฬ
๐ ) = ฬ
ฬ
ฬ
ฬ
ฬ
ฬ
ฬ
๐(๐ฅ๐ )
X3SAT
๐ is required to satisfy in each clause exactly one literal.
Naïve Algorithm: ๐(2๐ ๐(๐))
๐(๐ฅ๐ ) = ๐
Suppose ๐ฅ๐ appears in some ๐ถ = (๐ข๐ , ๐ข๐ , ๐ข๐ ). Suppose ๐ข๐ = ๐ฅ๐ .
Then must yield ๐(๐ข๐ ) = ๐(๐ข๐ ) = ๐.
Symmetrically, if ๐ข๐ = ๐ฅฬ
๐ we should set them to true.
If ๐(๐ฅ๐ ) = ๐น
๐ถ = (๐ฅ๐ , ๐ข๐ , ๐ข๐ ) โ ๐(๐ข๐ ) โ ๐(๐ข๐ ) โ
Get rid of ๐๐ and replace it by ๐ฅ๐ or ๐ฅฬ
๐
Canonical form: ๐ is in canonical form if each close contains 3 different variables.
Fact: If ๐ is not in canonical form, then it can be transformed into a shorter ๐ in canonical form
in polynomial time.
Idea: Suppose that ๐ is not canonical. Let ๐ = (๐ข1 , ๐ข2 , ๐ข3 ) be a clause violating the condition.
Clauses might already be simplified formulas and not necessarily the input.
Suppose (๐ข1 , ๐ข2 , ๐น), ๐ข2 = ๐ฅ2
We can discard ๐ข1 , replacing by ๐ฅ1 / ฬ
ฬ
ฬ
๐ฅ1 as needed
(๐ฅ1 , ๐ฅ1 , ๐ฅ1 ) โ not satisfyable
(๐ฅ1 , ๐ฅ1 , ฬ
ฬ
ฬ
)
๐ฅ1 โ ๐(๐ฅ! ) = ๐น
โฎ
(๐ฅ1 , ๐ฅ1 , ๐ฅ2 ) โ ๐(๐ฅ1 ) = ๐น, ๐(๐ฅ2 ) = ๐
Algorithm for X3SAT:
(1) Pick ๐ฅ๐ โ ๐
(2) ๐ โ ๐๐ธ๐๐(๐, ๐ฅ๐ , ๐)
(3) If ๐ = ๐ then return ๐.
(4) Else ๐ โ ๐๐ธ๐๐(๐, ๐ฅ๐ , ๐น) and return ๐.
Procedure ๐๐ธ๐๐(๐, ๐ฅ๐ , ๐ฃ)
(1) Set ๐(๐ฅ๐ ) โ ๐ฃ
(2) Canonize ๐ โ ๐โฒ .
a. If found contradicton while canonizing. Return ๐น.
b. If ๐ โฒ = โ
then return ๐.
(3) Run ๐3๐๐ด๐(๐โฒ ).
๐(๐) = max ๐๐ด (๐) over ๐ with n variables.
Suppos that there is a clause in which ๐ฅ๐ appear positively.
๐ = (๐ฅ๐ , ๐ข2 , ๐ข3 ). When you assign: ๐(๐ฅ๐ ) โ ๐ โ ๐(๐ข2 ) = ๐(๐ข3 ) = ๐น.
So ๐โฒ has at least 3 variables less.
(๐ฅโ๐ , ๐ข2 , ๐ข3 )
๐น
๐ข2 โก ๐ข
ฬ
ฬ
ฬ
3
So ๐โฒ has at least 2 variables less.
Case 2:
๐ = (๐ฅฬ
๐ , ๐ข2 , ๐ข3 )
๐
๐(๐) โค ๐(๐) + 2 โ ๐(๐ โ 2) โ ๐(๐) โค 2 2
๐(๐) โค ๐(๐) + 2๐ผ(๐โ2) + 2๐ผ(๐โ3)
2SAT
Clauses ๐๐ = (๐ข1๐ , ๐ข2๐ )
-------end of lesson 2
๐๐๐๐ ๐ก๐ ๐๐๐๐ฃ๐!
โค
2๐ผ๐
Maximum Independent Set on Planar Graphs
MIS-Planar Algorithm
1. Find a Separator ๐
2. For every Independent Set ๐0 โ ๐
a. Erase from ๐ด๐ all vertices adjacent to ๐0 along with their edges
b. Apply ๐1 โ MIS-Planar ()
c. Apply ๐2 โ MIS-Planar ()
d. ๐ โ ๐0 โช ๐1 โช ๐2
3. Return the largest ๐ seen
Correctness
Denote by ๐โ = Maximum Independent Set of ๐บ
๐โ = ๐0โ โช ๐1โ โช ๐2โ
๐0 = ๐0โ
๐(๐) = The maximum time complexity on ๐ vertex graph (in the worst case).
2
๐(๐) โค ๐1 ๐๐2โ๐ (๐2 ๐ + 2๐ ( ๐))
3
Guess that ๐(๐) โค 2๐ถ1 ๐
Exercise โ Verify!
A graph is planar if it does not contain a ๐พ5 or ๐พ33 as a sub-graph (minor).
Therefore, The clique problem on planar graph is not analogous to IS. The complementary graph
of a planar graph is not always a planar graph.
0-1 Knapsack
Input: Integers {๐, โฆ , ๐๐ }
Question: Is there a subset ๐ โ {๐1 , โฆ , ๐๐ } such that โ๐โ๐ ๐๐ = ๐ต ?
P.P. Algorithm ๐(๐๐ต)~2๐
๐
Now we will see a 2 2 algorithm.
Assume ๐ is even.
๐ด๐ผ {๐1 , โฆ , ๐๐ }
2
๐ด๐ฝ {๐๐+1 , โฆ , ๐๐ }
๐
๐พ = 22
Look at the sorted items of ๐ด๐ผ and ๐ด๐ฝ
๐
๐ = ๐1 โช ๐2
๐
๐1 โ {1, โฆ , }
2
๐
๐2 โ { + 1, โฆ , ๐}
2
Set ๐ = 0, ๐ = 2 โ 1
We check whether ๐ผ๐ + ๐ฝ๐ = ๐ต?
If itโs smaller than B โ ๐ = ๐ + 1
If itโs larger than B โ ๐ = ๐ โ 1
If it equals, weโre done!
We loop until either ๐ or ๐ reaches the end.
Claim: The algorithm is correct.
Proof: We need to show that if the algorithm returns no, then thereโs no solution.
By contradiction: Suppose there is some ๐ โ that solves the problem.
๐ โ = ๐1โ + ๐2โ ๐ . ๐ก. ๐1โ โ ๐1 , ๐2โ โ ๐2
By the definition of the algorithm, one of the indices had to explore the entire table since the
algorithm gave a negative answer.
Suppose ๐ reached the value ๐ โ before ๐ reached ๐ โ if at all.
But
๐ผ๐ + ๐ฝ๐ > ๐ผ๐โ + ๐ฝ๐โ
Since always larger than B. But then we should have advanced with ๐. But our situation stays the
same. So eventually ๐ will reach ๐ โ - contradiction.
๐
The time complexity at the moment is ๐ โ 2 2 . The additional ๐ factor is due to the initial sorting.
However, we can sort the subset linearly โ we just need to add the subsets containing a new
item and merge them with the old subsets till we have all subsets.
We still have that ๐ โ ๐ = ๐(2๐ )
What happens if we divide everything into ๐ tables?
๐ = ๐ (2
๐โ1
๐
๐ )
๐
๐ = ๐ (2๐ )
๐
๐ด๐ผ1 = {1, โฆ , }
๐
2nd description:
We will break ๐ด still into two sets โ ๐ด๐ผ and ๐ด๐ฝ .
๐
๐ด๐ผ = {1, โฆ , ๐ }
๐ด๐ฝ = the rest
We build only the table ๐ผ (sorted).
For every subset ๐ โ ๐ด๐ฝ do
๐ = โ ๐๐
๐๐ โ๐
๐ = ๐ตโ๐
Check if ๐ appears in the table ๐ผ.
(by binary search)
There are 2|๐ฝ| iterations = 2
๐โ1
๐
๐
iterations.
๐
๐
Each iteration takes time.
๐ = ๐ (๐ โ 2
๐โ1
๐
๐ )
๐
๐ = ๐ (2๐ )
We would like to show that we can do it in:
๐
๐ = ๐ (22 )
๐
๐ = ๐ (24 )
๐
๐พ = 24
๐
Lets divide everything into four parts (each size 4 ). Now lets treat each two parts as a single part
of size ๐2 . Denote the first โunifiedโ table as ๐ผ + ๐ฝ
Implementation of ๐ถ
By a priority queue ๐๐๐ผ+๐ฝ
๐
Storing ๐ (2 4 ) = ๐(๐พ) elements
Operations: Insert, Extract_min
Obviously we need all possible combinations of elements of ๐ผ and ๐ฝ. Therefore we can imagine
a matrix of all possible combinations.
At first, we will put just the first column in the queue. It is clear the value at 0,0 is the minimal
one - so the minimal one is already in the queue.
Whenever we take out a value from the queue, we will insert the value to its right.
Similarly, we can unite the last two ๐พ sized lists of subsets.
Exercise: Apply the technique for the following:
Exact Hitting set
Input: Universe
๐ = {๐ข1 , โฆ , ๐ข๐ }
Subsets ๐1 , โฆ , ๐๐ โ ๐
Question: Find ๐
โ ๐ touching each ๐๐ exactly once
(i.e. |๐
โฉ ๐๐ | = 1โ๐)
You can say that ๐ is no longer than ๐.
------ end of lesson 3
Theorem: If there exists a poly-time algorithm for finding a clique of size ๐ = log ๐ in a given
graph of size ๐, then there exists a poly-time algorithm for finding a clique of arbitrary size ๐ in
๐บ in time ~2๐(โ๐ log ๐) โค 2๐(โ๐ log ๐)
Proof: Suppose we are given a polytime algorithm for finding a clique of size ๐, โ๐ โค log ๐
Algorithm ๐ต[๐บ, ๐] (๐บ is arbitrary)
1. Construct ๐บฬ (๐ฬ , ๐ธฬ )
๐ฬ = {๐ โ ๐||๐| = โ๐}
๐
[|๐ฬ | = ๐ฬ = ( ) โค 2โ๐ log ๐ ]
โ๐
๐ธฬ = {(๐, ๐ โฒ )|๐ โฉ ๐ โฒ = โ
, ๐ โช ๐ โฒ ๐๐ ๐ ๐๐๐๐๐ข๐ ๐๐ ๐บ}
2. Apply ๐ด[๐บฬ , โ๐
]
And return itโs answer.
Observation 1: โ๐ < log ๐ฬ = โ๐ log ๐ โ ๐ด works in time ๐(๐ฬ๐ ) = ๐ (2๐(โ๐ log ๐) )
Observation 2: ๐บฬ has a โ๐-Clique โ ๐บ has a ๐-clique.
Approximation Algorithms
Optimization problem ๐.
Input ๐ผ
๐ โ (๐ผ) =Value of optimal solution of ๐ผ
Polytime algorithm for ๐ for input ๐ผ, return ๐๐ด (๐ผ).
We are interested in
|๐๐ด (๐ผ)โ๐โ (๐ผ)|
๐โ (๐ผ)
the error measure.
|๐๐ด (๐ผ)โ๐โ (๐ผ)|
โค๐
๐โ (๐ผ)
๐ (๐ผ)
For minimization: ๐๐ดโ (๐ผ) โค ๐. A
Definition 1: We say that ๐ด has approximation ratio ฯ if โInput ๐ผ
๐โ (๐ผ)
๐ด (๐ผ)
Definition 2: For maximization problems: ๐
โค ๐.
good
approximation is when 1 โค ๐
TSP
๐๐๐๐๐๐ โ ๐ cities, 1 โฆ ๐ and there was a distance between every two cities ๐๐๐
The goal is to find a cyclic tour that visits all cities, such that itโs shortest (has minimal distance).
Common Assumptions
(1) Symmetry: ๐๐๐ = ๐๐๐
(2) Triangle Inequality: ๐๐๐ โค ๐๐๐ + ๐๐๐
Cannot Approximate without Triangle Inequality
Theorem: If there is an approximation algorithm for ๐๐๐ (without triangle inequality) with ratio
๐ (up to exp(๐)) then ๐ = ๐๐
Proof: Suppose we have such an approximation algorithm ๐ด with ratio ๐.
We will use it to define a polynomial algorithm ๐ต for the Hamiltonian cycle problem.
Reminder: The Hamiltonian cycle problem has input ๐บ and the question is: Is there a cycle that
goes exactly once through every vertex?
Algorithm ๐ต gets an input ๐บ
Create A ๐๐๐ instance on ๐ cities (assuming that ๐บ is of size ๐).
(๐, ๐) โ ๐บ
1,
๐๐๐ = {
๐๐ + 2, ๐๐กโ๐๐๐ค๐๐ ๐
Now run ๐ด on this instance.
If ๐น๐ด [๐ผ] = ๐ return yes. Otherwise return no.
Claim: ๐บ has a Hamiltonian cycle โ ๐ต returns yes.
Proof:
G has no Hamiltonian cycle โ B surely returns no by definition of ๐ผ
๐บ has a Hamiltonian cycle๐ โ (๐) = ๐. Suppose ๐ต returns โnoโ. or ๐๐ด (๐ผ) > ๐. It means that
๐๐ด (๐ผ) โฅ (๐ โ 1) + (๐๐ + 2) โฅ (๐ + 1)๐ + 1
๐๐ด (๐ผ)โ๐โ (๐ผ)
๐โ (๐ผ)
โฅ
๐๐+1
๐
> ๐ โ ๐ด Does not have approximation ration ๐.
Nearest Neighbor Heuristics
Each step, you visit the closest city which you havenโt visited yet. A greedy procedureโฆ
This is the least efficient of the procedures weโll describe.
๐ โ
log ๐
This ๐ will probably be true for directed graphs as well.
Global Nearest Neighbor Heuristics
We hold a cycle at any given moment. We look for the city that can be added to the cycle such
that the cycle is minimal (of all possible cycles with the added city).
In this algorithm ๐ = 1 according to definition 1 and ๐ = 2 according to the second definition.
The Tree Algorithm
1. Construct a minimum spanning tree ๐ for ๐๐๐
2. Construct an Euler tour ๐ on ๐.
3. Shortcut the tour ๐ to a tour ๐ โฒ which visits every city exactly once.
We know ๐ค(๐ โฒ ) โค ๐ค(๐) (due to the triangle inequality)
๐ค(๐) โค 2๐ค(๐) Since
๐ โ - best tour.
But ๐ค(๐) โค ๐ค(๐๐โ ) โค ๐ค(๐ โ )
So we know ๐ค(๐ โฒ ) โค 2๐ค(๐ โ )
Definition 1: ๐ โค
|๐ค(๐โ )โ๐ค(๐โฒ )|
๐ค(๐โ )
Definition 2: ๐ โค
๐ค(๐โฒ )
๐ค(๐โ )
โค
โค
2๐ค(๐โ )
๐ค(๐โ )
2๐ค(๐โ )โ๐ค(๐โ )
๐ค(๐โ )
=1
โค2
Tight Exaple
TODO: Draw tight example
The tight example is a circle graph where each edge has a single edge to a vertex outside the
circle. The weight within the cycle is ๐ผ and the weight of every outer edge will be ๐ฝ. ๐ฝ โช ๐ผ.
๐ค(๐ โฒ ) = (๐ โ 1)๐ผ + 2๐ฝ + (๐ โ 1)(๐ผ + 2๐ฝ) โ 2๐(๐ผ + ๐ฝ)
๐
๐ค(๐ โ ) = ๐ โ ๐ผ + +๐๐ฝ + 2๐ฝ โ 2 โ ๐(๐ผ + 2๐ฝ)
So the ratio is โ 2.
Chrostofides
Euler Graph: All degrees are even. On an Euler graph you always have an Euler tour (if and only
if).
In any graph, the number of nodes of odd degree is even.
1.
2.
3.
4.
Build ๐๐๐ ๐
Select a weight matching ๐ on the odd degree vertices ๐.
Compute an Euler tour ๐ on ๐ โช ๐
Shortcut into ๐ โฒ
?
๐ค(๐) + ๐ค(๐) โค 1.5๐ค(๐ โ )
1
Prove: ๐ค(๐) โค 2 ๐ค(๐ โ )
Observe the tour ๐ โ.
Observe the tour ๐ฬ which is a tour of all the vertices of ๐.
Denote alternating edges of ๐ as ๐1 and ๐2 .
๐ฬ = ๐1 โช ๐2
๐1 , ๐2 are matchings on ๐.
๐ค(๐)
โค
๐ค(๐1 ), ๐ค(๐2 )
๐ถโ๐๐ ๐๐ ๐๐ ๐กโ๐ ๐๐๐
๐ค๐๐๐โ๐ก ๐๐๐ก๐โ๐๐ ๐๐ ๐
2๐ค(๐) โค ๐ค(๐1 ) + ๐ค(๐2 ) = ๐ค(๐ฬ) โค ๐ค(๐ โ )
Thightness
TODO: Draw the tightness example
----- end of lesson 4
Exercise 1: [Tree algorithm for TSP]
a) Describe a variant of the algorithm for the TSP path problem
b) Show ratio 2
c) Give a tight โbadโ example
๐-TSP
๐ salesman with an office located at some city. They can share the load. So we must construct ๐
different tours (Starting from the home city and ending there as well) that will traverse all cities.
The goal is to minimize the longest tour.
Paths: ๐1 , โฆ , ๐๐ . |๐ฬ| โฅ |๐๐ |
Minimize ๐๐ .
Heuristics
1. Compute the shortest โordinaryโ tour ๐ = โฉ๐1 , ๐2 , โฆ , ๐๐ , ๐1 โช
2. We would like to identify breakpoints โ {๐๐1 , โฆ , ๐๐๐โ1 }
3. Each agent will start with the city after a breakpoint, and return at the next breakpoint.
TODO: Draw the k-tour drawings
Denote ๐ฟ = |๐|
And denote: ๐๐๐๐ฅ = max {๐1๐ }
2โคiโคn
Choosing the breakpoints:
๐
(๐ฟ โ 2๐๐๐๐ฅ ) + ๐๐๐๐ฅ }
๐
1
Lemma 1: Each ๐๐ satisfies that |๐๐ | โค ๐ (๐ฟ โ 2๐๐๐๐ฅ ) + 2๐๐๐๐ฅ
๐๐ = max {1 โค ๐ โค ๐||๐[1 โ ๐๐ ]| โค
Proof:
For ๐ = 1:
Denote ๐1 as the edge from ๐๐1 back to point ๐1
1
๐
|๐๐ |: By choice of ๐1 , ๐ผ โค (๐ฟ โ 2๐๐๐๐ฅ ) + ๐๐๐๐ฅ
|๐1 | โค ๐๐๐๐ฅ
|๐1 | = ๐ผ + |๐1 | โค
1
(๐ฟ โ 2๐๐๐๐ฅ ) + 2๐๐๐๐ฅ
๐
๐ < ๐ < ๐:
Denote
By choice of ๐๐ ,๐๐+1
(*) ๐ผ + ๐ฝ >
๐โ1
(๐ฟ
๐
โ 2๐๐๐๐ฅ ) + ๐๐๐๐ฅ
๐
(**) ๐ผ + ๐ฝ + ๐พ โค ๐ (๐ฟ โ 2๐๐๐๐ฅ ) + ๐๐๐๐ฅ
1
(*)+(**) ๐พ โค ๐ (๐ฟ โ 2๐๐๐๐ฅ )
|๐๐ | = ๐พ + |๐1 | + |๐2 | โค
1
(๐ฟ โ 2๐๐๐๐ฅ ) + 2๐๐๐๐ฅ
๐
The only case left is ๐ = ๐. Left as an exercise.
1
1
Result 2: |๐ฬ| โค ๐ + 2 (1 โ ๐) ๐๐๐๐ฅ
๐ฬ โ - The best ๐ tour
๐ โ - the best tour
Lemma 3: |๐ โ | โค ๐|๐ฬ โ |
๐ โ โค |๐1โ โช ๐2โ โช โฆ โช ๐๐โ | โค ๐|๐ฬ โ |
Lemma 4:
|๐ฬ โ | โฅ 2๐๐๐๐ฅ
Lemma 5: If |๐| โค ๐ โ |๐ โ |
1
Then |๐ฬ| โค (๐ + 1 โ ) |๐ฬ โ |
๐
Proof:
๐ฟ
1
+ 2 (1 โ ) ๐๐๐๐ฅ
๐
๐
|๐ โ |
1
โค๐โ
+ 2 (1 โ ) ๐๐๐๐ฅ
๐
๐
๐|๐ โ |
1 1
โค๐โ
+ 2 (1 โ ) |๐ฬ โ |
๐
๐ 2
1
= ๐(๐ฬ โ ) + (1 โ ) |๐ฬ โ |
๐
|๐ฬ| โค
Bottleneck graph problems
๐ vertices
๐๐๐ ,
1 โค ๐, ๐ โค ๐
Triangle inequality holds.
๐-centers problem
๐-centers โ โณ โ ๐, |๐| = ๐
๐: {1, โฆ , ๐} โ โณ
โ๐ , ๐(๐) satisfies ๐๐,๐(๐) โค ๐๐,๐ โ๐ โ โณ
๐(โณ) = max{๐๐,๐(๐) }
i
Decision Version:
Input: {๐๐๐ }, ๐, ๐
Question: Is there โณ of size ๐ such that ๐(โณ) โค ๐?
๐ โ ๐ถ๐๐๐ก๐๐๐ ๐๐๐
Input: {๐๐๐ }, ๐
Question: Find โณ with minimal ๐(โณ)
Feasible Solution:
Edge subgraph
๐ป = (๐, ๐ธ โฒ ) with cost max(๐ป) = maxโฒ{๐๐๐ }
(i,j)โE
๐ข =Collection of feasible subgraphs
Optimal solution: ๐ป โ ๐ข such that max(๐ป) โค max(๐ป โฒ ) โ๐ป โฒ โ ๐ข
For the ๐ โ ๐ถ๐๐๐ก๐๐๐ problem:
๐ข๐โ๐ถ๐๐
= {๐ป|๐ป = ๐ ๐ ๐ก๐๐๐ ๐ค๐๐กโ ๐กโ๐ ๐ ๐๐๐๐ก๐๐๐ ๐๐ ๐๐๐๐ก๐ }
โณ = {๐1 , โฆ , ๐๐ }
Algorithm
๐ธ = {๐1 , ๐2 , โฆ } such that ๐๐1 โค ๐๐2 โค โฏ โค ๐๐๐(๐โ1)
2
๐โth bottleneck graph
๐๐(๐) = {๐, {๐1 , โฆ , ๐๐ }}
Algorithm A:
For ๐ = 1,2, โฆ do
๐บ๐ โ ๐๐(๐)
If ๐บ๐ contains an edge subgraph ๐ป such that ๐ป โ ๐ข then return ๐ป
Correctness:
๐ป found in ๐๐(๐)
max(๐ป) = ๐๐๐
Power Graphs
For some ๐ก โฅ 2, ๐บ = (๐, ๐ธ)
๐บ ๐ก = (๐, ๐ธ โฒ ) such that ๐ธ โฒ =
{(๐, ๐)|๐กโ๐๐๐ ๐๐ฅ๐๐ ๐ก๐ ๐ ๐๐๐กโ ๐๐ ๐๐ก ๐๐๐ ๐ก ๐ก ๐๐๐๐๐ ๐๐๐๐๐๐๐ก๐๐๐ ๐ ๐๐๐ ๐ ๐๐ ๐บ}
Claim: max(๐บ ๐ก ) โค ๐ก โ max(๐บ)
Proof: If (๐, ๐) โ ๐ธ โฒ (๐บ ๐ก )
๐๐๐ โค max(๐บ)
๐๐๐ โค ๐ก โ max(๐บ)
In the โifโ
Procedure ๐๐๐ ๐ก(๐บ๐ , ๐ก) returning:
1) Failure
2) Edge subgraph ๐ป of ๐บ๐๐ก such that ๐ป โ ๐ข
Algorithm B:
For ๐ = 1,2, โฆ do
๐บ๐ โ ๐๐(๐)
๐ฅ โ ๐๐๐ ๐ก(๐บ๐ , ๐ก)
If โ โFailureโ then return ๐ฅ and halt
Claim 2: If ๐๐๐ ๐ก complies with its specifications, then algorithm B has ratio ๐ก.
Proof: Suppose the algorithm stopped on iteration ๐. Test returned โfailureโ for 1, โฆ , ๐ โ 1
Which means there is no feasible solution using only ๐1 , โฆ , ๐๐โ1
โ ๐(โณ โ ) > ๐๐๐โ1 โฅ ๐๐๐
๐ป โ ๐บ๐๐ก = ๐๐(๐)๐ก โ ๐(โณ๐๐๐ ) โค max(๐ป) โค ๐ก โ ๐๐๐ โ
Implementing test for ๐-center
๐ก=2
๐๐๐ ๐ก(๐บ, 2):
1. Construct ๐บ 2
2. Find a maximal independent set in ๐บ 2 , โณ
3. If |โณ| > ๐ then return failure. Else return โณ
Claim: Test satisfies requirements 1+2.
2 is easy.
1 โ Suppose that test returns failure while there is an edge subgraph ๐ป in ๐บ such that ๐ป consists
of ๐ stars spanning ๐.
But since ๐ป โ ๐บ is a list of stars, after you square it you get a list of cliques. If there were at least
๐ stars, there are at least ๐ cliques and you canโt find a maximal larger idependent set.
Exercise 3: Give a tight โbad exampleโ.
Exercise 4: Prove that the greedy centers algorithm also yields an approximation ratio of 2.
(and give a tight example)
Lower bound:
If there is a polynomial time approximation algorithm for ๐ โ ๐๐๐๐ก๐๐๐ (with triangle inequality)
with ratio strictly less than 2, then ๐ = ๐๐
Proof sketch: Given an algorithm with ratio < 2 define a polynomial time algorithm for
dominating set.
Given ๐บ and ๐ (where the question is: Is there a dominating set of size at most ๐?)
1. Create instance of ๐-centers by setting ๐๐๐ = 1 if edge (๐, ๐) is in the graph and 0
otherwise
Another bottleneck problem:
Bottleneck TSP
Input: {๐๐๐ }
Question: Find a tour ๐ = โฉ๐1 , ๐2 , โฆ , ๐๐ , ๐1 โช such that max{๐๐๐ ,๐๐+1 } is minimized.
l
๐ข = {๐ก๐๐ข๐๐ ๐ ๐๐ ๐กโ๐ ๐๐๐ก๐๐๐ }
๐๐๐ ๐ก = max(๐)
Fact 1: Testing if a graph ๐บ is 2 connected is polynomial.
Fact 2: If ๐บ is not 2-connected, then it does not have a Hamiltonian cycle
Fact 3: If ๐บ is 2-connected โ ๐บ 2 has a Hamiltonian cycle (which can be constructed in polynomial
time).
--- end of lesson 5
Maximum independent set (MIS)
Input: graph ๐บ of size ๐
Question: Find largest independent set ๐โ
Known: No approximation algorithm with ration ๐1โ๐
Best known: Ratio ๐ โ
(log log ๐)2
log3 ๐
Algorithm A (Greedy MIS):
๐โโ
While ๐บ โ โ
do
- Pick lowest degree ๐ฃ
- ๐ โ ๐ โช {๐ฃ}
- Erase {๐ฃ } โช ฮ(๐ฃ) from ๐บ
This is not a good algorithmโฆ
Bad example:
TODO: Draw bad example
๐
Lemma 1: If the maximum degree of ๐บ is ฮ, then ๐ด will return |๐| โฅ ฮ+1
๐
Proof: Each iteration erases at most ฮ + 1 vertices from ๐บ โ # of iterations โฅ ฮ+1
And # of iterations = |๐|
1
Lemma 2: If ๐(๐บ) = ๐ (๐บ is ๐-colorable) then A will find ๐ of size |๐| โฅ 2 log k ๐
๐
(๐บ has |๐โ | โฅ ๐)
๐
Proof: ๐บ has ๐ vertices and ๐(๐บ) = ๐ โ โ colorclas of size โฅ ๐ โ The lowest degee in ๐บ is at
๐
๐
๐
๐
most ๐ โ โ This iteration will erase at most ๐ โ + 1 vectices
๐
1
๐(๐) โฅ 1 + ๐ (๐ โ 1) โ ๐(๐) โฅ 2 log k ๐
๐
Algorithm B (Greedy algorithm with ratio log ๐):
Partition ๐ into ๐1 , โฆ , ๐
๐
log ๐
For each ๐บ(๐๐ ) find MIS ๐๐
Return the largest ๐๐
TODO: Draw partitioning of the best empty set
|๐โ |
๐ log ๐
|๐โ |
๐
โค
|๐๐ต | log ๐
|๐๐ต | โฅ
A bad example is the empty set. Instead of taking all the nodes, we just take on of the sets.
Getting ratio
๐(log log ๐)2
log2 ๐
|๐โ | = ๐/๐พ
TODO: Draw ranges of ๐พ
Case โซ( ืโฌalgorithm A1):
If ๐พ โฅ log 2 ๐
๐
|๐โ | โค 2
log ๐
So we can just return a single vertex.
Case โซ( ืโฌalgorithm A2):
log ๐
< ๐พ < log 2 ๐
log log ๐
log ๐
1. ๐ก โ log log ๐
๐
2. Partition ๐ into sets ๐1 , โฆ , ๐ of size ๐๐ก
๐พ๐ก
3. In each ๐บ๐ = ๐บ(๐๐ )
Search for an independent set of size ๐ก
4. Return one of them
In ๐ because the number of cases:
log ๐
๐พ๐ก
( ) โค (๐พ๐ก)๐ก โค log 2 ๐ = (22๐๐๐ log ๐ )log log ๐ = 22 log ๐ = ๐2
๐ก
Claim: โ๐ such that ๐บ๐ contains an IS of size ๐ก
๐
Proof: |๐โ | = ๐
So โ๐ such that
๐โ
|๐โ โฉ ๐๐ | โฅ ๐ ๐ = ๐ก
โ๐พ๐ก
๐
โ
โ
|๐ |
๐
๐
๐โค
โค ๐=
=
๐ก
๐๐ก
|๐๐ด2 |
log ๐ 2
(
)
log log ๐
Case โซืโฌ:
๐
|๐โ | =
๐
๐พ const
Handling graphs without large cliques.
Graphs without triangles:
Algorithm ๐น[3, ๐บ]:
1. If ฮ(๐บ) < โ๐ (ฮ is the maximal degree)
then apply greedy algorithm ๐ด
2. Otherwise:
- Pick vertex ๐ฃ of degree ฮ
- Return ๐ = ฮ(๐ฃ)
ฮ(๐ฃ) โฅ โ๐
So ๐๐น โฅ โ๐
EX: Show that the following is a bad example
TODO: Draw bad example
Graphs with no cliques of size โฅ ๐:
Algorithm ๐น[๐พ, ๐บ]
๐ = 2 return ๐
๐ = 3: return ๐น[3, ๐บ]
๐ > 3:
1
If ฮ(๐บ) < ๐1โ๐โ1 then apply the greedy algorithm ๐ด
Else
1
-
Pick a vertex ๐ฃ of maximum degree ๐(๐ฃ) = ฮ โฅ ๐1โ๐โ1
๐ โ ๐น(๐ โ 1, ฮ(๐ฃ))
Return ๐
What is the ratio of the algorithm?
1
If ฮ < ๐1โ๐โ1
๐
Greedy finds |๐| โฅ ฮ+1 โฅ
๐
1
1โ
๐ ๐โ1
1
= ๐๐โ1
1
If ฮ โฅ ๐1โ๐โ1
1
๐โฒ = |ฮ(๐ฃ)| โฅ ๐1โ๐โ1
By the induction hypothesis ๐น(๐ โ 1, ฮ(๐ฃ)) returns |๐ | โฅ
|๐| โฅ
1
1 ๐โ1
1โ
(๐ ๐โ1 )
1
1
(๐โฒ )๐โ1
๐โ1
1
= ๐๐โ1
1
Claim: ๐น returns |๐| โฅ ๐ โ ๐๐โ1
๐
We know |๐โ | = ๐พ, K constant.
1
|๐โ | = ( + ๐ธ) ๐
๐
1
1
1
[๐ = 2๐พ, ๐ = ๐ โ ๐ + ๐ = ๐พ]
1
๐
1
Lemma: If |๐โ | = ( + ๐) ๐ then we can find |๐| โฅ (๐๐)๐โ1
We will now describe an algorithm called ๐น๐๐๐๐ (๐บ)
While ๐บ ha ๐ cliques
- Find a clique of size ๐
- Erase it from the graph
1
Claim: If there is an independent set of size (๐ + ๐๐) then ๐น๐๐๐๐ (๐บ) will leave us with a raph ๐บ โฒ
without ๐-cliques, |๐ฃ(๐บ โฒ )| โฅ ๐๐
Proof: ๐ฅ iterations
Erased ๐ฅ๐ vertices
๐ฅ๐ โค ๐
๐
๐ฅโค๐
Each iteration erased at most one ๐โ vertex
1
This means that at the end, ๐บ โฒ still contains at least (๐ + ๐) ๐ โ ๐ฅ vertices of ๐โ\
1
1
๐
( + ๐) ๐ โ ๐ฅ โฅ ( + ๐) ๐ โ = ๐๐
๐
๐
๐
|๐(๐บ โฒ )| โฅ ๐๐
A comment that doesnโt help us: Also, ๐บ โฒ still has an independent set of size โฅ ๐๐
Algorithm ๐ด4
- Apply ๐น๐๐๐๐ (๐บ)
- Apply ๐น(๐, ๐บ)
Case โซืโฌ:
|๐โ |๐
1
= ( + ๐) ๐,
๐
๐
โ After ๐น๐๐๐๐ we have
๐๐ด4 โค
1
๐
1
1
( ๐)๐โ1
๐
=๐
1
๐โ1
|๐(๐บ โฒ )|
โ๐
1
1โ
๐โ1
โฅ
1
๐
๐
๐ = 2๐พ,
โ ๐น finds |๐| โฅ
๐=
1
1
๐
1
1โ๐
(๐ ๐ )
๐
โโ
๐ ๐โ1 < 2 โ 1
So itโs not just a constant, itโs a small constant.
Cases โซืโฌ+โซืโฌ:
Ramseyโs Theorem:
In a graph of ๐ vertices
๐ +๐กโ2
โ๐ , ๐ก such that ๐ โฅ (
), ๐บ must contain either an ๐-clique or a ๐ก-independent set.
๐ โ1
(Can be found in polynomial time)
Algorithm ๐
(๐ , ๐ก, ๐):
1. If ๐ = 0 then return โ
as clique
If ๐ก = 0 return โ
as IS
2. Pick vertex ๐ฃ
๐พ โ |ฮ(๐ฃ)|
๐ +๐กโ3
3. If ๐พ โฅ (
) then do
๐ โ2
a. Apply ๐
(๐ โ 1 , ๐ก, ฮ(๐ฃ))
b. If found (๐ โ, 1)-clique ๐, then return ๐ โช {๐ฃ}
c. If found ๐ก-IS ๐, then return it
4. Else
a. ๐ โ ๐\({0} โช ฮ(๐ฃ))
๐ +๐กโ3
)]
[|๐| โฅ (
๐ โ1
b. Apply ๐
(๐ , ๐ก โ 1, ๐)
c. If found ๐-clique return it
d. If found ๐ก โ 1 independent set return ๐ โช {๐ฃ}
To prove the algorithm works, we must show inductively that the different options are correct.
Ex: Prove correctness of ๐
and of theorem.
2
Corolary: โ๐ โฅ 1 constant, โ๐บ of size ๐ [๐๐ โฅ ๐3 ]
log ๐
๐บ contains either a clique of size โฅ 2๐ log log ๐ or an IS of size โฅ ๐ก = log c ๐
Algorithm ๐ด3+4
๐
ฬ = log ๐ ]
[|๐โ | = ๐ for ๐พ < ๐พ
๐ log log ๐
log ๐
ฬ=
0. ๐พ โ 2๐พ
๐ log log ๐
1. Apply ๐
(๐ , ๐ก, ๐) with ๐ = ๐, ๐ก = log c ๐
(take ๐ = 2)
2. If found an IS o size ๐ก return it
3. If found clique of size ๐, erase it from ๐บ and goto(1)
--- end of lesson 6
Coloring
Theorem: If there exists an approximation algorithm for ๐๐ผ๐ with ratio ๐(๐) [non-decreasing]
then there exists an approximation for coloring with ratio ๐(๐) โ log ๐.
๐
We can even say something stronger. If ๐(๐) โ logฮฑ ๐ then the coloring has ratio 3๐(๐) or
something like that.
๐
Proof: Assume we have an algorithm ๐ด for ๐๐ผ๐ with ratio ~ logฮฑ ๐
Algorithm ๐ต for coloring:
1. ๐ โ 1
๐
2. While |๐| โฅ logฮฑ ๐ do
a. Invoke algorithm ๐ด, get independent set ๐ผ
b. Color ๐ผ vertices by ๐
c. Discard ๐ผ vertices by ๐
d. Discard ๐ผ vertices of their edges from ๐บ
e. ๐ โ ๐ + 1
3. Color each remaining vertex with a new color
Lemma 1: Algorithm ๐ด uses โค
3๐
๐
logฮฑ ๐
colors (where ๐ = chromatic number of the graph).
Proof: Suppose that there were m iterations. So we used ๐ colors in the WHILE loop. And the
number of colors at line 3 was ๐โฒ
๐
๐
We know that: ๐โฒ < logฮฑ ๐ โค logฮฑ ๐ ๐
Remains to show ๐ โค
2๐
๐
logฮฑ ๐
โ๐
๐๐ = iteration set at the beginning of stage ๐
๐บ๐ - graph at that stage
๐๐ = |๐๐ |
๐ผ๐ โ independent set colored at that stage
๐๐ โ chromatic number at that stage
๐ผ๐โ - maximal independent set of ๐บ๐
Claim 2: |๐ผ๐โ | โฅ
๐๐
๐
Proof: The chromatic number of a subset of the graph is smaller of equals to the chromatic
number of the original graph. There exists a subset ๐ โ ๐๐ such that ๐ is independent and
๐๐ ๐๐
|๐ผ๐โ | โฅ |๐| โฅ โฅ
๐๐
๐
Corollary: |๐ผ๐ | โฅ
logฮฑ ๐
2๐
Proof: From approximation ratio of ๐ด:
|๐ผ๐โ |
|๐ผ๐ |
โค ๐(๐๐ )
(*)
1
For sufficiently large ๐: log ฮฑ ๐๐ โฅ 2 log ฮฑ ๐
๐
because ๐๐ โฅ logฮฑ ๐. Why?
1
log ฮฑ ๐
2
1
log ๐ โ ๐ผ log log ๐ โฅ 2๐ผ log ๐ for sufficiently large ๐
log ฮฑ ๐๐ โฅ (log ๐ โ ๐ผ log log ๐)๐ผ โฅ
๐(๐๐ ) โค
๐๐
๐
โค
ฮฑ
log ๐ log ฮฑ ๐
|๐ผ๐โ |
|๐ผ๐ | =
๐(๐๐ )
๐๐ฆ (โ)
๐๐๐๐๐ 2
(โ)
โฅ
๐๐
โ๐
๐๐
โ1 ฮฑ
2 log ๐
๐1 = ๐
๐๐+1 = ๐๐ โ |๐ผ๐ | โค ๐๐ โ
โฅ
log ฮฑ ๐
2๐
log ฮฑ ๐
2๐
After ๐ โ 1 iterations
ฮฑ
log ๐
2๐
๐๐๐ ๐๐๐๐๐
๐๐๐๐ข๐โ ๐
โค
๐
log ฮฑ ๐
(๐
โค
๐
โค
๐
โ
โ
1)
๐โ1
log ฮฑ ๐
2๐
log ฮฑ ๐
2๐
๐
โค ๐,
๐โค
โ๐
2๐
log ฮฑ ๐
Algorithm DEG
ฮ = max degree of ๐บ
Color set {1, โฆ , ฮ + 1}
Consider 3-Colorable ๐บ.
TODO: Draw set of neighbors of ๐ฃ โ ฮ(๐ฃ)
Observation 1: โ๐ฃ. ๐บ(ฮ(๐ฃ)) is bipartite(โก 2 colorable).
Algorithm ๐ด:
a. ๐ โ 1
b. While ฮ(๐บ) โฅ โ๐ do
(1) Pick max degree ๐ฃ โ ๐บ
(2) Color ๐ฃ by ๐ + 2
(3) Color the vertices of ฮ(๐ฃ) by colors ๐, ๐ + 1
(4) Discard {๐ฃ} โช ฮ(๐ฃ) from ๐บ (and their edges)
(5) ๐ โ ๐ + 2
c. Color the remaining ๐บ using algorithm ๐ท๐ธ๐บ.
Note:
(1) Step ๐ uses at most โ๐ colors
(2) Step ๐3 is polynomial
(3) 2 colors per iteration
(4) # iterations โค โ๐
๐๐ด โค 2
โ๐ โค 3โ๐
โโ โ๐ + โ
๐
๐
๐
Slight improvement: ๐ (โlog ๐) colors. (there are ways to color a graph in ๐0.39 )
๐
1. While ฮ (๐บ) โฅ โlog ๐ do
a. ๐บ โฒ โ ๐บ
๐โโ
b. While ๐บ โฒ โ โ
and |๐| < log ๐ do
i. Pick max degree vertex ๐ฃ
ii. ๐ โ ๐ โช {๐ฃ}
iii. Discard from ๐บ โฒ {๐ฃ} โช ฮ(๐ฃ)
c. Examine every ๐ โ ๐, pick largest ๐ค โ ๐ such that ฮ(๐) (=โ๐ขโ๐ ฮ(๐ค)) is
bipartite
d. Discard from ๐บ the vertices ๐ โช ฮ(๐)
e. Color ๐ by a new color and ฮ(๐) by two new colors.
2. Apply DEG to the remaining vertices
We can always find a set ๐ โ ๐ such that |๐| โฅ
log ๐
3
such that ฮ(๐) is bipartite.
Claim:
๐
(1) Step 2 uses โค โlog ๐ colors
(2) Step 1 has ๐ iterations, ๐ โค
3๐
โ๐๐๐๐ ๐
1
๐
= 3โlog ๐
(3) Each iteration colors at least โฅ โฅ 3 โ๐๐๐๐ ๐ vertices
(4) Algorithm is in ๐ (the only suspicious step is c, and itโs OK because ๐ is logarithmic.
|๐| โฅ
log ๐
,
3
๐
1
ฮ(๐) โฅ |๐| โ โ
โฅ โ๐๐๐๐ ๐
log ๐ 3
Exercise: Consider the following problem:
Input: ๐บ(๐, ๐ธ) |๐| = ๐
๐(๐บ) = 3
๐ โ ๐, |๐| โค log ๐
Known; ๐ is independent and dominating
Question: Color ๐บ with ๐(log log ๐) colors.
Greedy Algorithm
Set Cover/Hitting Set
Input: Universe ๐ผ = {1, โฆ , ๐}
Subsets ๐1 , โฆ , ๐๐ โ๐. ๐๐ โ ๐ผ
SC: Collection of subsets.
๐ โ ๐ฝ = {1, โฆ , ๐}, such that โ๐พโ๐ ๐๐พ = ๐ผ
HS: Subset ๐
โ ๐ผ such that ๐
โฉ ๐๐ โ โ
โ๐
TODO: Draw matching between ๐ผ and ๐ฝ
So actually the question can be reduced to finding a dominating set in a bipartite graph (where
elements are on the left, sets are on the right, and you have an edge if the element is in the set).
The weighted version has weights on the edges and we are looking for the cheapest cover.
Greedy Algorithm for weighted set cover:
๐โโ
While ๐ผ โ โ
do
Find ๐ such that
๐๐
๐
is minimal
๐ โ ๐ โช {๐}
Discard the elements of ๐๐ from ๐ผ and from all their sets.
A tight bad example:
๐ผ = {1, โฆ , ๐}
๐ฝ = {1, โฆ , ๐ + 1}
1
๐ถ๐ = ,
๐๐ = {๐},
๐
๐๐+1 = ๐ผ
๐ถ๐+1 = 1 + ๐
1โค๐โค๐
By the greedy selection, we will pick: ๐๐ , ๐๐โ1 , โฆ , ๐1 in the first ๐ step.
1
1
1
๐ถ๐๐๐ = +
+. . + = ๐ป(๐)~ log ๐
๐ ๐โ1
1
๐ถ โ = ๐๐+1 = 1 + ๐
Tight bad example for the unwaited case:
TODO: Draw a picture of the universe
--- end of lesson 7
Greedy Algorithms โ Framework
๐ = {๐ข1 , โฆ , ๐ข๐ } universe.
Solution ๐ โ ๐.
Cost of ๐ข๐ = ๐๐
๐(๐) = โ ๐๐
๐ข๐ โ๐
Constraints โ feasability
Goal: Lowest cost feasible ๐.
Penalty: ๐: 2๐ โ โค+ โช {0}
๐ feasible โ ๐(๐) = 0
Requirements:
(A1) Penalty monotonicity โ ๐1 โ ๐2 โ ๐(๐1 ) โฅ ๐(๐2 )
To choose elements greedily โ ฮ(๐, ๐ข) = ๐(๐) โ ๐(๐ โช {๐ข})
(2) While ๐(๐) > 0 do
a) Choose ๐ข maximizing the ratio:
ฮ(๐,๐ข๐ )
๐๐
b) ๐ โ ๐ โช {๐ข๐ }
(A3) polinomiality:
Computing ๐(๐) is polynomial.
ฬ(๐, ๐ข)
Exercise: Suppose computing ฮ is NP hard, but you can, in polynomial time compute ฮ
ฬ(๐, ๐ข) โค 1 ฮ(๐, ๐ข)
such that ๐ฮ(๐, ๐ข) โค ฮ
๐
Suppose we are looking now at ๐. And suppose ๐ โ is the optimal set.
๐ฬ
= ๐ โ \๐ โmissingโ
Currently ฮ(๐, ๐ฬ
) = ๐(๐) โ ๐(๐
โ โช ๐ฬ
) = ๐(๐)
=0
(A2) โ๐ข๐โ๐ฬ
ฮ(๐, ๐ข๐ ) โฅ ๐(๐)
๐ โ = ๐(๐ โ )
โ๐ such that ๐(๐) > 0, denote by ๐ข(๐) = element added by the greedy algorithm.
Claim 1:
ฮ(๐, ๐ข(๐)) ๐(๐)
โฅ โ
๐๐ข(๐ )
๐
๐ฬ
= ๐ โ \๐ = {๐ข1 , โฆ , ๐ข๐๐ }
๐
(โ) โ ฮ (๐, ๐ข๐๐ ) โฅ ๐(๐)
๐=1
(โโ)๐(๐ โ ) = ๐ โ โฅ ๐(๐ฬ
)
(๐ด2)
โ๐๐=1 ฮ (๐, ๐ข๐๐ )
โ๐๐=1 ฮ(๐, ๐ข๐๐ ) (โโ) ๐(๐)
ฮ(๐, ๐ข(๐))
โฅ
=
โฅ
๐๐ข(๐)
๐โ
๐(๐ฬ
)
โ๐๐=1 ๐ (๐ข๐๐ )
We know that:
ฮ(๐, ๐ข(๐)) ฮ (๐, ๐ข๐๐ )
โฅ
๐๐ข(๐)
๐ (๐ข )
๐๐
(Because if โ๐ ๐ โฅ
(โโโ) ๐(๐ข(๐ )) โค
๐๐
๐๐
โ๐
โ ๐ โฅ โ ๐๐)
๐
๐ โ โ ฮ(๐, ๐ข(๐))
๐(๐)
Denote by ๐๐ = cost of the solution chosen by the greedy algorithm
Claim 2: ๐๐ โค ๐ป(๐(โ
)) โ ๐ โ \
1
2
1
3
Where ๐ป(๐) = 1 + + + โฏ +
1
๐
โ ln ๐
Proof: ๐ข1 , ๐ข2 , โฆ , ๐ข๐ are added to the solution by the greedy algorithm in the order which it
added them. Their cost: ๐1 , โฆ , ๐๐ .
ฮ1 , โฆ , ฮ๐ and ๐1 , โฆ , ๐๐ (penalty before iteration ๐)
๐(โ
) = ๐1
๐๐+1 = ๐๐ โ ฮ๐
๐๐+1 = 0
๐
๐๐ = โ ๐๐
๐=1
๐
๐
๐
๐
๐=1
๐=1
๐=1
๐๐+1 +1
๐ โ โ ฮ๐
ฮ๐
1
1
1
โค โ
= ๐โ โ โ โค ๐โ โ โ ( +
+ โฏ+
)=
๐๐
๐๐
๐๐ ๐๐ โ 1
๐๐ โ ฮ๐ + 1
(โโโ)
1
1
1
1
๐โ โ โ ( +
+โฏ+
) = ๐โ โ โ
= ๐ โ โ ๐ป(๐1 ) = ๐ โ โ ๐ป(๐(โ
)) โ
๐๐ ๐๐ โ 1
๐๐+1 + 1
๐
๐=1
๐=๐1
Stronger (but more convenient) version of (A2)
(A2โ) โ๐ข, ๐1 , ๐2 . ๐1 โ ๐2 โ ฮ(๐1 , ๐ข) โฅ ฮ(๐2 , ๐ข)
Claim 3: (๐ด2โฒ ) โ (๐ด2) Exercise โ prove!
Example: Set-Cover.
๐ = {1, โฆ , ๐} corresponding to sets ๐1 , โฆ , ๐๐ โ ๐ผ
Constraints:
๐ผ = {1, โฆ , ๐}
Feasible solution: ๐
โ ๐ such that โ๐โ๐
๐๐ = ๐ผ
We would like to minimize the cost of ๐
such that ๐
is feasible.
1. Define penalty:
๐(๐
) = # elements f ๐ผ not in โ๐โ๐
๐๐ = |๐ผ\ โ๐โ๐
๐๐ |
๐(โ
) = ๐, ๐(๐) = 0 assuming โ๐โ๐
๐๐ = ๐ผ
(A1) V
(A3) V
(Aโ2)
Suppose we have ๐
1 = {๐๐1 , โฆ , ๐๐๐ } adding ๐๐ reduces ๐ by ๐
Then for ๐
1 โ ๐
1
๐
2 = {๐๐1 , โฆ , ๐๐๐ , ๐๐๐ +1 , โฆ , ๐๐๐ }
Adding ๐๐ to ๐
2 will reduce ๐ by at most ๐
Exercise: prove formally!
Example:
K-Set cover
Choose min0cost collection of sets (from ๐1 , โฆ , ๐๐ ) such that each element ๐ โ ๐ผ appears in at
least ๐ sets.
Exercise: Choose ๐. Show A1,A2โ,A3
Min test-set:
๐ผ = {1, โฆ , ๐}
๐1 , โฆ , ๐๐ and choose ๐
โ {1, โฆ , ๐} such that for every 2 elements: ๐, ๐ โ ๐ผ there is ๐ โ ๐
such
that ๐๐ contains exactly one of ๐ add ๐.
Some centers problem:
Input: ๐บ(๐, ๐ธ), distances ๐(๐ข, ๐ฃ) โ โค+
๐: ๐ โ โค+ demand vertex ๐ฃ needs ๐(๐ฃ) units.
Cost of opening a facility in ๐ฃ๐ = ๐๐
Solution = ๐ โ ๐ where facilities are opened.
๐(๐) = โ ๐๐
๐ฃ๐ โ๐
Goal: pick min-cost ๐ such that โ client ๐ฃ, ๐(๐ฃ) โ ๐๐๐ ๐ก(๐ฃ, ๐๐๐๐(๐, ๐ฃ)) โค ๐
HittingSet problem:
๐ = {๐ข1 , โฆ , ๐ข๐ },
๐ฎ = {๐1 , โฆ , ๐๐ }
Solution: ๐ โ ๐
๐ hits ๐๐ if ๐ โฉ ๐๐ โ โ
Feasible solution: hits every ๐๐
Dual-HittingSet problem:
Input: ๐, ๐ฎ, ๐
Goal: Select ๐ โ ๐, |๐| = ๐
Maximize the number of sets hit.
The optimum: |๐ โ | = ๐ = {๐ข1โ , โฆ , ๐ข๐โ } hitting ๐ sets of ๐ฎ. ๐ฎ โ โ ๐ฎ = sets hit by ๐ โ. |๐ฎ โ | = ๐
1
โ greedy yields |๐ฎ๐ | = ๐ hitting at least โฅ (1 โ ๐) โ ๐
1
2
But we will only show it hits โฅ ๐
Greedy chooses:
๐ฅ
๐ข1 โ๐ข๐โ hitting โฅ ๐ sets. Gains ๐1 hits.
๐ฅ
๐1 โฅ
๐
|๐ฎ โ | = ๐
๐ฎ2โ = ๐ฎ โ \{sets hit by ๐ข1 }
|๐ฎ2โ | โฅ ๐ โ ๐1
โ๐ข๐โ hitting โฅ
(๐โ๐1 )
๐
sets of ๐ฎ2โ
๐ข2 gains ๐2 hits
(๐ฅ โ ๐1 )
๐2 โฅ
๐
โฆ
๐ข๐ gains ๐๐ โฅ
๐โ๐1 โ๐2 ,โฆ,๐๐โ1
๐
๐ โ ๐1 โฅ ๐
๐ โ ๐2 + ๐1 โฅ ๐
๐๐๐ + ๐๐โ1 + ๐๐โ2 + โฏ + ๐1 โฅ ๐
Hitting ๐1 + ๐2 + โฏ + ๐๐
But we will not show it!
Instead we will show:
๐ โ๐๐ข๐๐ ๐๐
โฅ
1
(1 โ ๐) ๐
๐๐๐ + (๐ + 1)๐๐โ1 + โฏ + (2๐ โ 2)๐2 + (2๐ โ 1)๐1 โฅ ๐ โ ๐
(2๐ โ 1)(๐๐ + ๐๐โ1 + โฏ + ๐2 + ๐1 ) โฅ ๐ โ ๐
๐
๐๐๐๐๐๐๐ฆ = โ ๐๐ โฅ
๐=1
๐
๐
๐โฅ
2๐ โ 1
2
Comment 1: The bound is tight (there are examples).
Conclude: OPT needs more than ๐ โ 1 elements to hit all sets
--- end of lesson
Hit-all Algorithm
Vertex cover.
Input: Algorithm ๐บ(๐, ๐ธ)
Question: Find the smallest set of vertices ๐ถ such that every edge is touched.
๐ถโโ
While ๐ธ โ โ
do
Pick ๐ = โฉ๐ข, ๐ฃโช โ ๐ธ
๐ถ โ ๐ถ โช {๐ข, ๐ฃ}
Discard from ๐ธ all โtouchedโ edges
If we were to solve it using a greedy algorithm:
๐(โ
) = |๐ธ|
Ratio โค ln|๐ธ| โค 2 ln ๐
Bad example for a greedy algorithm:
TODO: Draw bad example for a greedy algorithm
Back to the hit-all algorithm
Suppose we chose ๐ = {๐1 , . . , ๐๐ } edges considered by the algorithm.
๐ =maximal matching
๐ถ๐๐๐ = 2๐
๐ถโ โฅ ๐
Set Cover
๐ = {1, โฆ , ๐},
๐1 , โฆ , ๐๐
deg(๐) = # sets ๐๐ such that ๐ โ ๐๐
ฮ(๐ฎ) = max{deg(๐)}
i
Exercise: Hit-all algorithm has approximation ratio ฮ.
Greedy algorithm to weighted set cover
๐ถ1 , โฆ , ๐ถ๐
๐ถ๐ - the cost of using ๐๐
The greedy algorithm does the following:
1. ๐ผ โ โ
2. While ๐ โ โ
do
๐ถ
a. Find ๐ such that |๐๐| is minimum
๐
b. ๐ผ โ ๐ผ โช {๐}
c. Discard from ๐ผ and every remaining ๐๐โฒ the element ๐ โ ๐๐
Theorem: Approximation โค ln ๐
Proof: ๐ = max{|๐๐ |}
๐๐๐๐๐๐๐ฆ = ๐ป(๐)
Representing ๐๐๐ถ as an integer linear program
Linear Programming
{๐ฅ1 , โฆ , ๐ฅ๐ }
Minimize โ๐๐=1 ๐๐ ๐ฅ๐
Subject to:
๐11 ๐ฅ1 + โฏ + ๐1๐ ๐ฅ๐ โฅ ๐1
โฎ
๐๐1 ๐ฅ1 + โฏ + ๐๐๐ ๐ฅ๐ โฅ ๐๐
Or: min ๐ฬ
๐ฅฬ
such that ๐ด๐ฅฬ
โฅ ๐ฬ
๐ฅ๐ โฅ 0
In our case, ๐ฅ๐ โ {0,1}
We want to choose a subset of the set ๐1 , โฆ , ๐๐ so the variables will be ๐ฅ1 , โฆ , ๐ฅ๐ and their
intended interpretation will be that ๐ฅ1 should get the value of 1 if set ๐ 1 is selected to the cover,
and 0 otherwise.
1,
๐๐ ๐ ๐๐๐๐๐ก๐๐ ๐ก๐ ๐กโ๐ ๐๐๐ฃ๐๐
๐ฅ๐ โ {
0,
๐๐กโ๐๐๐ค๐๐ ๐
Minimize โ๐๐=1 ๐ฅ๐ ๐๐
Such that โ๐ โ ๐ (๐ โค ๐ โค ๐). โ๐๐โ๐ ๐ฅ๐ โฅ 1
Since we need integer linear programming, the problem is NP hard!
This is what we call a primal linear program.
Dual Linear Programming
{๐ฆ1 , โฆ , ๐ฆ๐ }
The dual would be to maximize โ๐ ๐๐ ๐ฆ๐ subject to ๐ด๐ ๐ฆฬ
โค ๐ฬ
.
Refer to ๐ฅฬ
, ๐ฆฬ
feasible solutions if they satisfy their constraints (respectively).
And denote by ๐ฅฬ, ๐ฆฬ the optimal solutions to the primal and the dual (respectively).
Weak LP-Duality Theorem
If ๐ฅฬ
is feasible for the primal LP, and ๐ฆฬ
is feasible for the dual LP, then:
๐ฬ
๐ฅฬ
โฅ ๐ฬ
๐ฆฬ
Proof:
๐
๐ฬ
๐ฅฬ
= โ ๐๐ ๐ฅ๐
๐๐ฆ ๐กโ๐ ๐๐ข๐๐ ๐
๐๐๐๐ ๐ก๐๐๐๐๐ก
โฅ
๐=1
๐
๐
๐
โ (โ ๐๐๐ ๐ฆ๐ ) ๐ฅ๐ = โ (โ ๐๐๐ ๐ฅ๐ ) ๐ฆ๐
๐=1
๐=1
๐=1
๐๐ฆ ๐กโ๐ ๐๐๐๐๐๐ ๐
๐๐๐๐ ๐ก๐๐๐๐๐ก๐
โฅ
๐=1
โ ๐๐ ๐ฆ๐ = ๐ฬ
๐ฆฬ
๐=1
The (not weak) LP duality theorem is: ๐ฬ
๐ฅฬ = ๐ฬ
๐ฆฬ
Cost Decomposition
Suppose that in iteration ๐ก of the greedy algorithm, it chose some set denoted ๐๐๐ก .
๐พ๐ก = {๐|๐ ๐๐ ๐ ๐ก๐๐๐ ๐๐ ๐๐๐ก ๐๐ก ๐๐ก๐๐๐๐ก๐๐๐ ๐ก}
For every ๐ โ ๐พ๐ก :
๐๐
๐๐๐๐๐(๐) = ๐ก
๐พ๐ก
๐ถ๐๐๐๐๐๐ฆ = โ โ ๐๐๐๐๐(๐) = โ ๐๐๐ก =
๐ก ๐โ๐พ๐ก
๐ก
Guessing a solution for the dual-weighted set cover.
Dual Weighted Set Cover
max โ๐
๐=1 ๐ฆ๐ such that โ ๐โ๐๐ ๐ฆ๐ โค ๐๐ โ1 โค ๐ โค ๐
๐ฆ๐ โฅ0
Guessed ๐ฆฬ
๐๐๐๐๐(๐)
๐ฆ๐ =
๐ป(๐)
(for ๐ = max|๐๐ |)
Claim: ๐ฆฬ
is a feasible solution for dual-weighted set cover.
Proof: Need to show that โ๐, โ๐โ๐๐
๐๐๐๐๐(๐)
๐ป(๐)
โค ๐๐ or โ๐โ๐๐ ๐๐๐๐๐(๐) โค ๐๐ โ ๐ป(๐)
๐๐ = {๐1 , โฆ , ๐๐ } ordered by the ordering the greedy algorithm covered them. If two elements are
covered in the same iteration, we donโt care about the ordering.
Suppose ๐๐ was covered in iteration ๐ก (by ๐๐๐ก )
๐๐
๐๐๐๐๐(๐๐ก ) = ๐ก
|๐พ๐ก |
Why didnโt the algorithm choose ๐๐ ?
By choosing ๐๐ we would have paid ๐๐ .
๐๐
๐
๐
So we know |๐พ๐ก| โค ๐โ(๐+1)
.
๐ก
๐
๐
๐
๐ง=1
๐ง=1
๐=1
๐๐
1
โ ๐๐๐๐๐(๐) = โ ๐๐๐๐๐(๐๐ง) โค โ
= ๐๐ โ = ๐๐ ๐ป(๐) โค ๐๐ ๐ป(๐)
๐โ๐+1
๐
๐โ๐๐
๐๐๐๐๐๐๐ฆ = โ ๐๐๐๐๐(๐)
๐
๐ป๐ โ ๐ฬ
๐ฅฬ
โโ
๐โ๐๐๐๐ ๐๐
๐ฆ๐
=
โ ๐ป๐ ๐ฆ๐ = ๐ป๐ โ 1ฬ
โ ๐ฆฬ
๐๐ฟ๐โ๐๐ข๐๐
โค
๐ป๐ โ ๐ฬ
โ
โ
๐ฅฬ
๐๐๐ก๐๐๐๐
๐๐๐๐๐๐
(๐๐๐๐๐ก๐๐๐๐๐)
๐ ๐๐๐ข๐ก๐๐๐
๐
= ๐ป๐ ๐ถ โ
๐๐๐ก๐๐๐๐
๐ ๐๐๐ข๐ก๐๐๐
๐๐๐ ๐กโ๐
๐ผ๐ฟ๐
Example: Cover by 3 paths
Input: graph ๐บ = (๐, ๐ธ) of ๐ vertices
Question: cover the vertices by a minimum collection of paths of length 3.
1 1 11
๐๐๐๐๐๐๐ฆ = ๐ป(3) = 1 + + =
2 3
6
3
Exercise: Show algorithm with ๐๐ด โค 2. With Bonus!
Exercise 2: Show polynomial algorithms for paths for length is 2.
Deterministic rounding
Vertex Cover
ILP
Variables: ๐ฅ๐ for each ๐ฃ๐
1,
๐ฃ๐ โ ๐
๐ฅ๐ = {
0,
๐๐กโ๐๐๐ค๐๐ ๐
Minimize โ๐ ๐ฅ๐
Subject to ๐ฅ๐ + ๐ฅ๐ โฅ 1, ๐ฅ๐ โ {0,1}, โ๐ = {๐ฃ๐ , ๐ฃ๐ }
LP
โค
0 โค ๐ฅ๐ โค 1
In polytime, find optimum ๐ฅฬ
Rounded integeral solution:
1
1,
๐ฅ
ฬ
โฅ
โฒ
๐
๐ฅ๐ โ {
2
0,
๐๐กโ๐๐๐ค๐๐ ๐
Observation: โ๐, ๐ฅ๐โฒ โค 2๐ฅฬ๐
Claim 1: ๐ฅฬ
โฒ is a feasible solution to the ILP-VC.
Proof: Consider any edge ๐ = โฉ๐ฃ๐ , ๐ฃ๐ โช
The LP had a constraint: ๐ฅ๐ + ๐ฅ๐ โฅ 1
1
2
1
2
Therefore, we know that ๐ฅฬ๐ + ๐ฅฬ๐ โฅ 1 โ either ๐ฅฬ๐ โฅ or ๐ฅฬ๐ โฅ . This means that either ๐ฅ๐โฒ or ๐ฅ๐โฒ
was set to 1. Which means that either ๐ฃ๐ โ ๐ or ๐ฃ๐ โ ๐.
Claim 2: ๐๐ท๐
โค 2๐ถ โ
๐๐ท๐
= โ ๐ฅ๐โฒ โค โ 2๐ฅฬ๐ โค 2 โ
๐
โ
๐ฬ
๐๐๐ก ๐๐๐
๐ ๐๐๐ข๐ก๐๐๐
๐
Generalization to Weighted Set Cover
ฮ = max{deg(๐)}
i
Hit-allโ ๐ = ฮ
1) Write ILP for Weighted Set Cover
2) Solve relaxed SP, get ๐ฅฬ (fractional)
1
1,
๐ฅฬ๐ โฅ
ฮ
3) Round by setting ๐ฅ๐โฒ โ {
0, ๐๐กโ๐๐๐ค๐๐ ๐
1,
๐ฅฬ๐ > 0
3โ) ๐ฅ๐โฒ โ {
0, ๐๐กโ๐๐๐ค๐๐ ๐
โค 2 โ ๐โ
© Copyright 2026 Paperzz