part i
play

Part I bers, t - target number Question: Is there a subset of X such - PowerPoint PPT Presentation

Subset Sum Subset Sum Instance : X = { x 1 , . . . , x n } n integer positive num- Part I bers, t - target number Question: Is there a subset of X such the sum of its elements is t ? Subset Sum SolveSubsetSum ( X , t , M ) b [ 0 . . . Mn ] -


  1. Subset Sum Subset Sum Instance : X = { x 1 , . . . , x n } – n integer positive num- Part I bers, t - target number Question: Is there a subset of X such the sum of its elements is t ? Subset Sum SolveSubsetSum ( X , t , M ) b [ 0 . . . Mn ] - boolean array init to false . // b [ x ] is true if x can be realized M : Max value // as a subset of X . input numbers. b [ 0 ] ← true . for i = 1 , . . . , n do � Mn 2 � R.T. O . for j = Mn down to x i do b [ j ] ← b [ j − x i ] ∨ b [ j ] return b [ t ] Subset Sum Subset Sum Efficient algorithm??? Two-approximation Lemma 1. Algorithm solving Subset Sum in O ( Mn 2 ) . 1. ( X , t ) ; Given instance of Subset Sum . γ opt ≤ t : Opt. 2. M might be prohibitly large... 3. if M = 2 n = 2. = ⇒ Compute legal subset with sum ≥ γ opt / 2 . ⇒ algorithm is not polynomial time. 4. Subset Sum is NPC . 3. Running time O ( n log n ) . 5. Still want to solve quickly even if M huge. Proof. 6. Optimization version: 1. Sort numbers in X in decreasing order. Subset Sum Optimization 2. Greedily - add numbers from largest to smallest (if Instance : ( X , t ) : A set X of n positive integers, possible). and a target number t . 3. s : Generates sum. Question: The largest number γ opt one can repre- 4. u : First rejected number. s ′ : sum before rejection. sent as a subset sum of X which is smaller or equal 5. s ′ > u > 0 , s ′ < t , and s ′ + u > t = ⇒ to t . t < s ′ + u < s ′ + s ′ = 2 s ′ = ⇒ s ′ ≥ t / 2 .

  2. Polynomial Time Approximation Schemes Polynomial Time Approximation Schemes 1. Example: Approximation algorithm with running time Definition ( PTAS ) O ( n 1 /ε ) is a PTAS . PROB : Max imization problem. Algorithm with running time O ( 1 /ε n ) is not. ε > 0 : approximation parameter. 2. Fully polynomial... A ( I , ε ) is a polynomial time approximation scheme Definition ( FPTAS ) ( PTAS ) for PROB : � � � � � � An approximation algorithm is fully polynomial time 1. ∀ I : ( 1 − ε ) � opt ( I ) � ≤ � A ( I , ε ) � ≤ � opt ( I ) � , � � � � � � approximation scheme ( FPTAS ) if it is a PTAS , and its 2. | opt ( I ) | : opt price, running time is polynomial both in n and 1 /ε . 3. | A ( I , ε ) | : price of solution of A . 3. Example: PTAS with running time O ( n 1 /ε ) is not an 4. A running time polynomial in n for fixed ε . FPTAS . For minimization problem: 4. Example: PTAS with running time O ( n 2 /ε 3 ) is an | opt ( I ) | ≤ | A ( I , ε ) | ≤ ( 1 + ε ) | opt ( I ) | . FPTAS . Approximating Subset Sum Approximating Subset Sum Looking again at the exact algorithm Subset Sum Approx Instance : ( X , t , ε ) : A set X of n positive integers, a ExactSubsetSum ( S , t ) target number t , and parameter ε > 0 . n ← | S | Question: A number z that one can represent as a subset P 0 ← { 0 } for i = 1 . . . n do sum of X , such that ( 1 − ε ) γ opt ≤ z ≤ γ opt ≤ t . P i ← P i − 1 ∪ ( P i − 1 + x i ) Remove from P i all elements > t return largest element in P n 1. S = { a 1 , . . . , a n } x + S = { a 1 + x , a 2 + x , . . . a n + x } 2. Lists might explode in size.

  3. Trim the lists... Trim the lists... Definition Trim ( L ′ , δ ) ApproxSubsetSum ( S , t ) L ← Sort ( L ′ ) For two positive real // S = { x 1 , . . . , x n } , L = � y 1 . . . y m � Trim ( L ′ , δ ) numbers z ≤ y , the // x 1 ≤ x 2 ≤ . . . ≤ x n curr ← y 1 L ← Sort ( L ′ ) n ← | S | , L 0 ← { 0 } , δ = ε/ 2 n number y is a L = � y 1 . . . y m � L out ← { y 1 } for i = 1 . . . n do δ -approximation to z if for i = 2 . . . m do curr ← y 1 E i ← L i − 1 ∪ ( L i − 1 + x i ) y if y i > curr · ( 1 + δ ) L out ← { y 1 } 1 + δ ≤ z ≤ y . L i ← Trim ( E i , δ ) Append y i to L out for i = 2 . . . m do Remove from L i elems > t . if y i > curr · ( 1 + δ ) curr ← y i return largest element in L n Observation return L out Append y i to L out If x ∈ L ′ then there exists a curr ← y i return L out number y ∈ L out such that y ≤ x ≤ y ( 1 + δ ) , where L out ← Trim ( L ′ , δ ) . Analysis Proof continued 1. E i list generated by algorithm in i th iteration. Proof continued 2. P i : list of numbers (no trimming). 1. If x ∈ P i \ P i − 1 = ⇒ x = α + x i , for some α ∈ P i − 1 . Claim 2. By induction, ∃ α ′ ∈ L i − 1 s.t. α ′ ≤ α ≤ ( 1 + δ ) i − 1 α ′ . For any x ∈ P i there exists y ∈ L i such that 3. Thus, α ′ + x i ∈ E i . y ≤ x ≤ ( 1 + δ ) i y . 4. ∃ x ′ ∈ L i s.t. x ′ ≤ α ′ + x i ≤ ( 1 + δ ) x ′ . Proof 5. Thus, x ′ ≤ α ′ + x i ≤ α + x i = x ≤ ( 1 + δ ) i − 1 α ′ + x i ≤ 1. If x ∈ P 1 then follows by observation above. ( 1 + δ ) i − 1 ( α ′ + x i ) ≤ ( 1 + δ ) i x ′ . ⇒ (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 . Therefore y ≤ y ′ ≤ x ≤ ( 1 + δ ) i − 1 y ′ ≤ ( 1 + δ ) i y .

  4. Running time of ApproxSubsetSum Running time of ApproxSubsetSum Lemma Observation For x ∈ [ 0 , 1 ] , it holds e x / 2 ≤ ( 1 + x ) . In a list generated by Trim , for any number x , there are no two numbers in the trimmed list between x and ( 1 + δ ) x . Lemma Lemma For 0 < δ < 1 , and x ≥ 1 , we have � � ( n /ε 2 ) log n | L i | = O , for i = 1 , . . . , n . log 1 + δ x ≤ 2 ln x � ln x � = O . δ δ See notes for a proof of lemmas. Running time of ApproxSubsetSum Running time of ApproxSubsetSum Proof. Lemma ε log 2 n � n 3 � The running time of ApproxSubsetSum is O . 1. L i − 1 + x i ⊆ [ x i , ix i ] . 2. Trimming L i − 1 + x i results in list of size Proof. 1. Running time of ApproxSubsetSum dominated by total ix i � ln i � � ln n � log 1 + δ = O = O , length of L 1 , . . . , L n . x i δ δ � n 3 � � 2. Above lemma implies | L i | = O ε log n . 3. Now, δ = ε/ 2 n , and i 3. Trim sorts lists. i th iteration R.T. O ( | L i | log | L i | ) . � ln n � � n ln n � ε log 2 n � n 3 � 4. Overall, R.T. O ( � i | L i | log | L i | ) = O . | L i | ≤ | L i − 1 | + O ≤ | L i − 1 | + O δ ε � n 2 log n � = O . ε

  5. ApproxSubsetSum Theorem ApproxSubsetSum returns u ≤ t , s.t. γ opt 1 + ε ≤ u ≤ γ opt ≤ t , γ opt : opt solution. ( n 3 /ε ) log 2 n � � Running time is O . Proof. 1. Running time from above. 2. γ opt ∈ P n : optimal solution. 3. ∃ z ∈ L n , such that z ≤ opt ≤ ( 1 + δ ) n z 4. ( 1 + δ ) n = ( 1 + ε/ 2 n ) n ≤ e ε/ 2 ≤ 1 + ε, since 1 + x ≤ e x for x ≥ 0 . 5. γ opt / ( 1 + ε ) ≤ z ≤ opt ≤ t .

Recommend


More recommend