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 โ ๐∗