Coping with NP Hardness

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 โˆ™ ๐‘โˆ—