approximation algorithms
play

Approximation Algorithms Subset Sum III Instance : X = { x 1 , . . - PowerPoint PPT Presentation

NEW CS 473: Theory II, Fall 2015 Subset Sum Approximation Algorithms Subset Sum III Instance : X = { x 1 , . . . , x n } n integer positive num- bers, t - target number Question: subset of X s.t. sum of its elements is t ? Lecture 10


  1. NEW CS 473: Theory II, Fall 2015 Subset Sum Approximation Algorithms Subset Sum III Instance : X = { x 1 , . . . , x n } – n integer positive num- bers, t - target number Question: ∃ subset of X s.t. sum of its elements is t ? Lecture 10 September 24, 2015 Assume x 1 , . . . , x n are all ≤ n . Then this problem can be solved in (A) The problem is still NP-Hard , so probably exponential time. (B) O ( n 3 ) . (C) 2 O (log 2 n ) . (D) O ( n log n ) . (E) None of the above. 1/41 2/41 Subset Sum Subset Sum Efficient algorithm??? Subset Sum 1. Algorithm solving Subset Sum in O ( Mn 2 ) . Instance : X = { x 1 , . . . , x n } – n integer positive num- 2. M might be prohibitly large... bers, t - target number 3. if M = 2 n = ⇒ algorithm is not polynomial time. Question: ∃ subset of X s.t. sum of its elements is t ? 4. Subset Sum is NPC . 5. Still want to solve quickly even if M huge. SolveSubsetSum ( X , t , M ) 6. Optimization version: b [0 . . . Mn ] ⇐ false // b [ x ] is true if x can be Subset Sum Optimization M : Max value // realized by subset of X . input numbers. Instance : ( X , t ) : A set X of n positive integers, b [0] ← true . and a target number t . for i = 1 , . . . , n do � Mn 2 � R.T. O . Question: The largest number γ opt one can repre- for j = Mn down to x i do sent as a subset sum of X which is smaller or equal b [ j ] ← B [ j − x i ] ∨ B [ j ] to t . return B [ t ] 3/41 4/41

  2. Subset Sum Polynomial Time Approximation Schemes 2 -approximation Definition ( PTAS ) Lemma PROB : Max imization problem. 1. ( X , t ) ; Given instance of Subset Sum . γ opt ≤ t : Opt. ε > 0 : approximation parameter. 2. = ⇒ Compute legal subset with sum ≥ γ opt / 2 . A ( I , ε ) is a polynomial time approximation scheme 3. Running time O ( n log n ) . ( PTAS ) for PROB : � � � � � � 1. ∀ I : (1 − ε ) � opt( I ) � ≤ � A ( I , ε ) � ≤ � opt( I ) � , � � � � � � Proof. 2. | opt( I ) | : opt price, 1. Sort numbers in X in decreasing order. 3. | A ( I , ε ) | : price of solution of A . 2. Greedily - add numbers from largest to smallest (if 4. A running time polynomial in n for fixed ε . possible). For minimization problem: 3. s : Generates sum. | opt( I ) | ≤ | A ( I , ε ) | ≤ (1 + ε ) | opt( I ) | . 4. u : First rejected number. s ′ : sum before rejection. 5. s ′ > u > 0 , s ′ < t , and s ′ + u > t = ⇒ t < s ′ + u < s ′ + s ′ = 2 s ′ = ⇒ s ′ ≥ t / 2 . 5/41 6/41 Polynomial Time Approximation Schemes Approximating Subset Sum 1. Example: Approximation algorithm with running time Subset Sum Approx O ( n 1 /ε ) is a PTAS . Instance : ( X , t , ε ) : A set X of n positive integers, a Algorithm with running time O (1 /ε n ) is not. target number t , and parameter ε > 0 . 2. Fully polynomial... Question: A number z that one can represent as a sub- Definition ( FPTAS ) set sum of X , such that (1 − ε ) γ opt ≤ z ≤ γ opt ≤ t . An approximation algorithm is fully polynomial time approximation scheme ( FPTAS ) if it is a PTAS , and its running time is polynomial both in n and 1 /ε . 3. Example: PTAS with running time O ( n 1 /ε ) is not a FPTAS . 4. Example: PTAS with running time O ( n 2 /ε 3 ) is a FPTAS . 7/41 8/41

  3. Approximating Subset Sum Trim the lists... Looking again at the exact algorithm Definition L ′ : Inc. sorted list of numbers For two positive real ExactSubsetSum ( S , t ) Trim ( L ′ , δ ) numbers z ≤ y , the n ← | S | L = � y 1 . . . y m � number y is a P 0 ← { 0 } curr ← y 1 δ -approximation to z if for i = 1 . . . n do y L out ← { y 1 } 1 + δ ≤ z ≤ y . P i ← P i − 1 ∪ ( P i − 1 + x i ) for i = 2 . . . m do Remove from P i all elements > t if y i > curr · (1 + δ ) Observation Append y i to L out If x ∈ L ′ then there exists return largest element in P n curr ← y i a number y ∈ L out such return L out that y ≤ x ≤ y (1 + δ ) , 1. S = { a 1 , . . . , a n } where L out ← Trim( L ′ , δ ) . x + S = { a 1 + x , a 2 + x , . . . a n + x } 2. Lists might explode in size. 9/41 10/41 Trim the lists... Understanding trimming ApproxSubsetSum ( S , t ) Trim ( L ′ , δ ) // S = { x 1 , . . . , x n } , L = � y 1 . . . y m � // x 1 ≤ x 2 ≤ . . . ≤ x n curr ← y 1 n ← | S | , L 0 ← { 0 } , L out ← { y 1 } δ = ε/ 2 n for i = 2 . . . m do for i = 1 . . . n do if y i > curr · (1 + δ ) E i ← L i − 1 ∪ ( L i − 1 + x i ) Append y i to L out L i ← Trim( E i , δ ) curr ← y i Remove from L i elems > t . return L out return largest element in L n E i : Computed by merging two sorted lists in linear time. 11/41 12/41

  4. Remark Analysis 1. E i list generated by algorithm in i th iteration. 1. Can assume that trimmed lists L i are sorted... 2. P i : list of numbers (no trimming). 2. Algorithm: E i ← L i − 1 ∪ ( L i − 1 + x i ) Claim 3. So, this is just copy, shift, and merge of two sorted lists. For any x ∈ P i there exists y ∈ L i such that 4. ... resulting in a sorted lest. y ≤ x ≤ (1 + δ ) i y . 5. takes linear time in size of lists. Proof 1. If x ∈ P 1 then follows by observation above. ⇒ (induction) ∃ y ′ ∈ L i − 1 s.t. 2. If x ∈ P i − 1 = y ′ ≤ x ≤ (1 + δ ) i − 1 y ′ . 3. By observation ∃ y ∈ L i s.t. y ≤ y ′ ≤ (1 + δ ) y , As such, y ≤ y ′ ≤ x ≤ (1 + δ ) i − 1 y ′ ≤ (1 + δ ) i y . 13/41 14/41 Proof continued Running time of ApproxSubsetSum Proof continued Lemma For x ∈ [0 , 1] , it holds exp( x / 2) ≤ (1 + x ) . 1. If x ∈ P i \ P i − 1 = ⇒ x = α + x i , for some α ∈ P i − 1 . 2. By induction, ∃ α ′ ∈ L i − 1 s.t. α ′ ≤ α ≤ (1 + δ ) i − 1 α ′ . Lemma 3. Thus, α ′ + x i ∈ E i . For 0 < δ < 1 , and x ≥ 1 , we have 4. ∃ x ′ ∈ L i s.t. x ′ ≤ α ′ + x i ≤ (1 + δ ) x ′ . log 1+ δ x ≤ 2 ln x � ln x � = O . 5. Thus, δ δ x ′ ≤ α ′ + x i ≤ α + x i = x ≤ (1 + δ ) i − 1 α ′ + x i ≤ (1 + δ ) i − 1 ( α ′ + x i ) ≤ (1 + δ ) i x ′ . See notes for a proof of lemmas. 15/41 16/41

  5. Running time of ApproxSubsetSum Running time of ApproxSubsetSum Observation Proof. In a list generated by Trim , for any number x , there are no 1. L i − 1 + x i ⊆ [ x i , ix i ] . two numbers in the trimmed list between x and (1 + δ ) x . 2. Trimming L i − 1 + x i results in list of size Lemma � � ix i � ln i � � ln n � | L i | = O ( n /ε ) log n , for i = 1 , . . . , n . log 1+ δ = O = O , x i δ δ 3. Now, δ = ε/ 2 n , and � ln n � n ln n � � | L i | ≤ | L i − 1 | + O ≤ | L i − 1 | + O δ ε � n 2 log n � = O . ε 17/41 18/41 Running time of ApproxSubsetSum ApproxSubsetSum Lemma Theorem � � n 3 The running time of ApproxSubsetSum is O ε log n . ApproxSubsetSum returns u ≤ t , s.t. γ opt 1+ ε ≤ u ≤ γ opt ≤ t , Proof. γ opt : opt solution. � ( n 3 /ε ) log n � Running time is O . 1. Running time of ApproxSubsetSum dominated by total length of L 1 , . . . , L n . Proof. 2. Above lemma implies 1. Running time from above. n × n 2 � n 3 � � � � | L i | = O ε log n = O ε log n . 2. γ opt ∈ P n : optimal solution. i 3. ∃ z ∈ L n , such that z ≤ opt ≤ (1 + δ ) n z 3. Trim runs in time proportional to size of lists. � ε 4. (1 + δ ) n = (1 + ε/ 2 n ) n ≤ exp � ≤ 1 + ε, since � � n 3 2 4. Overall, R.T. O ε log n . 1 + x ≤ e x for x ≥ 0 . 5. γ opt / (1 + ε ) ≤ z ≤ opt ≤ t . 19/41 20/41

  6. Maximal matching An example of the greedy algorithm... 1. G = (V , E) 2. Compute maximal matching... 1 1 6 6 3. X ⊆ E which is maxim al and independent. 10 10 4. Maximal = can not improved by adding an edge. 20 20 20 3 3 3 5. Maximum = largest possible set among all possible sets. 11 11 6. Computing the maximum is hard then computing 2 2 9 9 maximal solution. 13 13 13 7. Q: Find maximal matching quickly and of large size... 15 15 15 4 4 17 17 14 14 12 8 12 8 5 5 19 19 19 16 7 18 16 7 18 16 21/41 22/41 Maximal matching: Algorithm Maximal matching: Result Theorem 1. Algorithm: Repeatedly pick an arbitrary edge and remove it. Given a graph G one can compute in O ( n + m ) time, a maximal matching with at least | X | / 2 edges, where X is the 2. M : Generated matching. X : Maximal matching. size of the maximum (optimal) matching. 3. Clearly a maximal matching... 4. This is a 2 -approximation to the maximum matching. 5. Because... 6. Every edge in M “kills” two edges of X in the worst case. 23/41 24/41

  7. Bin packing Bin packing: First fit Problem definition Analysis Bin Packing Instance : v : Bin size. S = { α 1 , . . . , α n } : n items α i : size of i th item. Target: Find min # B , and a decomposition S 1 , . . . , S B Lemma of S , such that ∀ j � x ∈ S j ≤ v . First fit is a 2 -approximation. Proof. 1. ∪ i S i = S and ∀ i � = j S i ∩ S j = ∅ . Observe that only one bin can have less than v / 2 content in 2. NP-Hard from Partition . it... 3. NP-Hard to approximate within 3 / 2 . 4. Natural problem... 5. How to approximate? 6. First fit: Have a row of bins, insert items greedily into the first bin that fits them. 7. First fit decreasing: Sort the elements first... 25/41 26/41 An example Independent set of rectangles Algorithm: Divide & Conquer Input Independent set of rectangles. Assume: Open rectangles. 27/41 28/41

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend