Advanced Algorithms COMS31900 Approximation algorithms part three - - PowerPoint PPT Presentation
Advanced Algorithms COMS31900 Approximation algorithms part three - - PowerPoint PPT Presentation
Advanced Algorithms COMS31900 Approximation algorithms part three (Fully) Polynomial Time Approximation Schemes Rapha el Clifford Slides by Benjamin Sach Approximation Algorithms Recap An algorithm A is an -approximation algorithm for
Approximation Algorithms Recap
An algorithm A is an α-approximation algorithm for problem P if,
- A runs in polynomial time
- A always outputs a solution with value s
- Here P is an optimisation problem with optimal solution of value Opt
- If P is a maximisation problem, Opt
α
s Opt
within an α factor of Opt
- If P is a minimisation problem, Opt s α · Opt
We have seen: a 3/2-approximation algorithm for Bin Packing a 2-approximation algorithm for k-centers a 3/2-approximation algorithm for scheduling multiple machines
The Subset Sum problem
4 4 7 3
2 2 t = 12
The Subset Sum problem
4 4 7 3
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
|S| = m
The Subset Sum problem
4 4 7 3
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12
|S| = m
The Subset Sum problem
4 4 7 3
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t?
|S| = m
The Subset Sum problem
4 4 7 3
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? the size of S′ is
a∈S′ a
|S| = m
The Subset Sum problem t = 12
4 4
2
7 3
2
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? the size of S′ is
a∈S′ a
|S| = m
The Subset Sum problem t = 12
7 3
2
4 4
2
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? the size of S′ is
a∈S′ a
|S| = m
The Subset Sum problem t = 12
7 3
2
4 4
2
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? the size of S′ is
a∈S′ a
|S| = m
The Subset Sum problem
4 4 7 3
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? the size of S′ is
a∈S′ a
|S| = m
The Subset Sum problem
4 4 7 3
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? Optimisation Problem the size of S′ is
a∈S′ a
Find the size of the largest subset of S which is no larger than t
|S| = m
The Subset Sum problem
4 4 7 3
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? Optimisation Problem the size of S′ is
a∈S′ a
Find the size of the largest subset of S which is no larger than t
|S| = m
The Subset Sum problem
7
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? Optimisation Problem the size of S′ is
a∈S′ a
Find the size of the largest subset of S which is no larger than t
4 4 3
|S| = m
The Subset Sum problem
7
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? Optimisation Problem the size of S′ is
a∈S′ a
Find the size of the largest subset of S which is no larger than t
4 4 3
|S| = m
The answer to the
- ptimisation problem is ‘11’
The Subset Sum problem
4 4 7 3
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? Optimisation Problem the size of S′ is
a∈S′ a
Find the size of the largest subset of S which is no larger than t
|S| = m
The Subset Sum problem
4 4 7 3
2 2 t = 12
- Let S be a multi-set of positive integers and t be a positive integer
here S = {4, 2, 4, 7, 2, 3} and t = 12 Decision Problem Is there a subset, S′ ⊆ S with size t? Optimisation Problem the size of S′ is
a∈S′ a
The optimisation version is NP-hard and the decision version is NP-complete Find the size of the largest subset of S which is no larger than t
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
4 4 7 3
2 2 S S3 |S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
4 4 7 3
2 2 S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
4 4 7 3
2 2 S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
2
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
4
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
2
4
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
4 4
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
2
4 4
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
2
4 4
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm
2
4 4
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
2
4 4
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
2
4 4
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
2
4 4
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t (here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
L3 + s4 = L3 + 7 =
{7, 9, 11}
(here t = 12)
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
7
L3 + s4 = L3 + 7 =
{7, 9, 11}
(here t = 12)
|S| = m
s4
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
2
7
L3 + s4 = L3 + 7 =
{7, 9, 11}
(here t = 12)
|S| = m
s4
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
4 7
L3 + s4 = L3 + 7 =
{7, 9, 11}
(here t = 12)
|S| = m
s4
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
2
4 7
L3 + s4 = L3 + 7 =
{7, 9, 11}
(here t = 12)
|S| = m
s4
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
7 4 4
L3 + s4 = L3 + 7 =
{7, 9, 11}
(here t = 12)
|S| = m
s4
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
2
7 4 4
L3 + s4 = L3 + 7 =
{7, 9, 11}
(here t = 12)
|S| = m
s4
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
2
4 4 7
2 L3 + s4 = L3 + 7 =
{7, 9, 11} L4 = {0, 2, 4, 6, 7, 8, 9, 10, 11}
(here t = 12)
|S| = m
s4
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
S S3
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
L3 =
{0, 2, 4, 6, 8, 10}
The largest subset of S (of size at most t) is the largest number in Lm We compute Li from Li−1:
Li = Li−1 ∪ (Li−1 + si)
where (x + si) ∈ (Li−1 + si) iff x ∈ Li−1 and x + si t
2
4 4 7
2 L3 + s4 = L3 + 7 =
{7, 9, 11} L4 = {0, 2, 4, 6, 7, 8, 9, 10, 11}
(here t = 12) We don’t have any duplicates in Li - so |Li| t
|S| = m
s4
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt)
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n?
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
Input
n words
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
Input
n words
a w bit word
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
Input
n words
a w bit word (conventionally w ∈ Θ(log n))
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
Input
n words
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
Input
n words
The input to the Subset Sum problem is a list of the elements of S along with t encoded in binary in a total of n words
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
Input
n words
The input to the Subset Sum problem is a list of the elements of S along with t encoded in binary in a total of n words
s1 s2 s3 t
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
Input
n words
The input to the Subset Sum problem is a list of the elements of S along with t encoded in binary in a total of n words
s1 s2 s3 t
As m n, the time is O(nt)
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
Input
n words
The input to the Subset Sum problem is a list of the elements of S along with t encoded in binary in a total of n words
s1 s2 s3 t
As m n, the time is O(nt) . . . but t could be (for example) 2n
|S| = m
An exact solution
The algorithm
- Let L0 = {0}
- For i = 1 . . . m:
- Compute (Li−1 + si) from Li−1
- Compute Li = Li−1 ∪ (Li−1 + si)
- Output the largest number in Lm
O(1) time O(|Li−1|) time O(|Li|) time O(|Lm|) time
Each Li is of length |Li| t The overall time complexity is therefore O(mt) Is this polynomial in n? What even is n?
n is the length of the input (measured in words)
Input
n words
The input to the Subset Sum problem is a list of the elements of S along with t encoded in binary in a total of n words
s1 s2 s3 t
As m n, the time is O(nt) . . . but t could be (for example) 2n
|S| = m
. . . in other words O(n2n) time!
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c The algorithm for Subset Sum given takes O(nt) = O(nc+1) time (in this case)
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c The algorithm for Subset Sum given takes O(nt) = O(nc+1) time (in this case)
So there is a pseudo-polynomial time algorithm for Subset Sum
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c The algorithm for Subset Sum given takes O(nt) = O(nc+1) time (in this case)
So there is a pseudo-polynomial time algorithm for Subset Sum
A diversion into computational complexity
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c The algorithm for Subset Sum given takes O(nt) = O(nc+1) time (in this case) We say that an NP-complete problem is weakly NP-complete if there is a pseudo-polynomial time algorithm for it
So there is a pseudo-polynomial time algorithm for Subset Sum
A diversion into computational complexity
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c The algorithm for Subset Sum given takes O(nt) = O(nc+1) time (in this case) We say that an NP-complete problem is weakly NP-complete if there is a pseudo-polynomial time algorithm for it The decision version of Subset Sum is weakly NP-complete
So there is a pseudo-polynomial time algorithm for Subset Sum
A diversion into computational complexity
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c The algorithm for Subset Sum given takes O(nt) = O(nc+1) time (in this case) We say that an NP-complete problem is weakly NP-complete if there is a pseudo-polynomial time algorithm for it We say that an NP-complete problem is strongly NP-complete if it remains NP-complete when all the numbers are integers nc The decision version of Subset Sum is weakly NP-complete
So there is a pseudo-polynomial time algorithm for Subset Sum
A diversion into computational complexity
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c The algorithm for Subset Sum given takes O(nt) = O(nc+1) time (in this case) We say that an NP-complete problem is weakly NP-complete if there is a pseudo-polynomial time algorithm for it We say that an NP-complete problem is strongly NP-complete if it remains NP-complete when all the numbers are integers nc The decision version of Subset Sum is weakly NP-complete The decision version of Bin packing is strongly NP-complete
So there is a pseudo-polynomial time algorithm for Subset Sum
A diversion into computational complexity
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c The algorithm for Subset Sum given takes O(nt) = O(nc+1) time (in this case) We say that an NP-complete problem is weakly NP-complete if there is a pseudo-polynomial time algorithm for it We say that an NP-complete problem is strongly NP-complete if it remains NP-complete when all the numbers are integers nc The decision version of Subset Sum is weakly NP-complete The decision version of Bin packing is strongly NP-complete
So there is a pseudo-polynomial time algorithm for Subset Sum
A diversion into computational complexity (this only makes sense if you rephrase the problem)
Pseudo-polynomial time algorithms
We say that an algorithm is pseudo-polynomial time
if it runs in polynomial time when all the numbers are integers nc for some constant c The algorithm for Subset Sum given takes O(nt) = O(nc+1) time (in this case) We say that an NP-complete problem is weakly NP-complete if there is a pseudo-polynomial time algorithm for it We say that an NP-complete problem is strongly NP-complete if it remains NP-complete when all the numbers are integers nc The decision version of Subset Sum is weakly NP-complete The decision version of Bin packing is strongly NP-complete
So there is a pseudo-polynomial time algorithm for Subset Sum
A diversion into computational complexity item sizes are integers in [nc]
4
bins have size
t ∈ [nc]
(this only makes sense if you rephrase the problem)
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.01 so that A0.01 also runs in polynomial time and
- utputs a subset of size at least Opt
1.01 > 0.99 · Opt
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.01 so that A0.01 also runs in polynomial time and
- utputs a subset of size at least Opt
1.01 > 0.99 · Opt
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
Let ǫ = 0.001 so that A0.001 also runs in polynomial time and
- utputs a subset of size at least Opt
1.001 > 0.999 · Opt
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
A PTAS does not have to have a time complexity which is polynomial in 1/ǫ
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
A PTAS does not have to have a time complexity which is polynomial in 1/ǫ
Aǫ can have a time complexity of O(n
c ǫ ) for example
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
A PTAS does not have to have a time complexity which is polynomial in 1/ǫ
Aǫ can have a time complexity of O(n
c ǫ ) for example
O(n10c) vs. O(n100c) vs. O(n1000c) in our example
ǫ = 0.1 ǫ = 0.01 ǫ = 0.001
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
A PTAS does not have to have a time complexity which is polynomial in 1/ǫ
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
A PTAS does not have to have a time complexity which is polynomial in 1/ǫ A fully PTAS (FPTAS) has a time complexity which is polynomial in 1/ǫ (as well as polynomial in n)
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
A PTAS does not have to have a time complexity which is polynomial in 1/ǫ A fully PTAS (FPTAS) has a time complexity which is polynomial in 1/ǫ (as well as polynomial in n) i.e. the time complexity is O((n/ǫ)c) for some constant c
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P
- If we had a PTAS for Subset Sum we could:
Let ǫ = 0.1 so that A0.1 runs in polynomial time and
- utputs a subset of size at least Opt
1.1 > 0.9 · Opt
A PTAS does not have to have a time complexity which is polynomial in 1/ǫ A fully PTAS (FPTAS) has a time complexity which is polynomial in 1/ǫ (as well as polynomial in n) i.e. the time complexity is O((n/ǫ)c) for some constant c In our example O((10n)c) = O((100n)c) = O((1000n)c) = O(nc)
ǫ = 0.1 ǫ = 0.01 ǫ = 0.001
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t (where Si = {s1, s2, . . . , si} - the first i numbers in the input)
3 S S4
L4 = {0, 2, 4, 6, 7, 8, 9, 10, 11} 2
4
2 2
4 7
(here t = 12)
4
2
4 7 4 4 7
2
4 4
2
7 4
A PTAS for Subset Sum
The exact algorithm for Subset Sum was slow (in general) because each list of possible subset sizes Li could become very large Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t (where Si = {s1, s2, . . . , si} - the first i numbers in the input)
3 S S4
L4 = {0, 2, 4, 6, 7, 8, 9, 10, 11} 2
4
2 2
4 7
(here t = 12)
4
2
4 7 4 4 7
2
4 4
2
7 4
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
For every y ∈ Li, there is a z ∈ L′
i which is almost as big
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
For every y ∈ Li, there is a z ∈ L′
i which is almost as big
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
Consider this process called Trim. . . Trim(Li, δ): Include Li[j] in L′
i iff
where prev is the previous
Li[j] > (1 + δ) · prev
entry we included in L′
i
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
For every y ∈ Li, there is a z ∈ L′
i which is almost as big
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
Consider this process called Trim. . . Trim(Li, δ): Include Li[j] in L′
i iff
where prev is the previous
L4 = {0, 2, 4, 6, 7, 8, 9, 10, 11} 2
4
2
4 7 4 4 7
2
4 4
2
7 4 Li[j] > (1 + δ) · prev
entry we included in L′
i
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
For every y ∈ Li, there is a z ∈ L′
i which is almost as big
for δ = 1. . . L′
4 = {0, 2, 6}
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
Consider this process called Trim. . . Trim(Li, δ): Include Li[j] in L′
i iff
where prev is the previous
L4 = {0, 2, 4, 6, 7, 8, 9, 10, 11} 2
4
2
4 7 4 4 7
2
4 4
2
7 4 Li[j] > (1 + δ) · prev
entry we included in L′
i
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
For every y ∈ Li, there is a z ∈ L′
i which is almost as big
for δ = 1. . . L′
4 = {0, 2, 6}
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
Consider this process called Trim. . . Trim(Li, δ): Include Li[j] in L′
i iff
where prev is the previous
L4 = {0, 2, 4, 6, 7, 8, 9, 10, 11} 2
4
2
4 7 4 4 7
2
4 4
2
7 4 Li[j] > (1 + δ) · prev
entry we included in L′
i
L′
4 is a small subset of L4 and for any y ∈ L4,
there is an z ∈ L′
4 with z y/2
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
For every y ∈ Li, there is a z ∈ L′
i which is almost as big
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
Consider this process called Trim. . . Trim(Li, δ): Include Li[j] in L′
i iff
where prev is the previous
Li[j] > (1 + δ) · prev
entry we included in L′
i
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
For every y ∈ Li, there is a z ∈ L′
i which is almost as big
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
Consider this process called Trim. . . Trim(Li, δ): Include Li[j] in L′
i iff
where prev is the previous
Li[j] > (1 + δ) · prev
entry we included in L′
i
Unfortunately, this hasn’t really achieved anything. . .
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
For every y ∈ Li, there is a z ∈ L′
i which is almost as big
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
Consider this process called Trim. . . Trim(Li, δ): Include Li[j] in L′
i iff
where prev is the previous
Li[j] > (1 + δ) · prev
entry we included in L′
i
Unfortunately, this hasn’t really achieved anything. . . we don’t have time to compute Li and then trim it
(because Li might be very big)
A PTAS for Subset Sum
Recall that Li is the set of sizes of all S′ ⊆ Si which are not larger than t Key Idea Construct a trimmed version of Li (denoted L′
i ⊆ Li) so that
The length of L′
i is polynomial in the input length (i.e. |L′ i| nc for some c)
For every y ∈ Li, there is a z ∈ L′
i which is almost as big
(where Si = {s1, s2, . . . , si} - the first i numbers in the input)
L′
i is a subset of Li (i.e. L′ i ⊆ Li)
Consider this process called Trim. . . Trim(Li, δ): Include Li[j] in L′
i iff
where prev is the previous
Li[j] > (1 + δ) · prev
entry we included in L′
i
Unfortunately, this hasn’t really achieved anything. . . we don’t have time to compute Li and then trim it Instead, we will trim as we go along. . .
(because Li might be very big)
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
Trim(U, δ): Include U[j] in L′
i iff U[j] > (1 + δ) · prev
where prev is the previous thing we included in L′
i
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
2 2
4 L′
i−1 =
si = 3 |S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
2 2
4 L′
i−1 =
si = 3
2
(L′
i−1 + si) =
3 3 |S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
2 2
4 L′
i−1 =
si = 3
2
(L′
i−1 + si) =
U = L′
i−1 ∪ (L′ i−1 + si) = 2 2
4
2
3 4 3 3 3
2
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
2 2
4 L′
i−1 =
si = 3
2
(L′
i−1 + si) =
U = L′
i−1 ∪ (L′ i−1 + si) = 2 2
4
2
3
= L′
i = Trim(U, δ)
2
(with δ = 1)
4 3 3 3
2 2
3 |S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
2 2
4 L′
i−1 =
si = 3
2
(L′
i−1 + si) =
U = L′
i−1 ∪ (L′ i−1 + si) = 2 2
4
2
3
= L′
i = Trim(U, δ)
2
(with δ = 1)
4 3 3 3
keep each thing if it is more than (1 + δ) times as big as the last thing you kept
2 2
3 |S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i−1|) time
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i−1|) time
O(|L′
i|) time
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i−1|) time
O(|L′
i|) time
- Let L′
i = Trim(U, δ)
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
Trim(U, δ): Include U[j] in L′
i iff U[j] > (1 + δ) · prev
where prev is the previous thing we included in L′
i
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i−1|) time
O(|L′
i|) time
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
Trim(U, δ): Include U[j] in L′
i iff U[j] > (1 + δ) · prev
where prev is the previous thing we included in L′
i
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i−1|) time
O(|L′
i|) time
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i−1|) time
O(|L′
i|) time
This algorithm throws away some possible subsets,
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
but it always outputs a valid subset (but probably not the largest one) Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i−1|) time
O(|L′
i|) time
This algorithm throws away some possible subsets, Two questions remain. . .
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
but it always outputs a valid subset (but probably not the largest one) Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i−1|) time
O(|L′
i|) time
This algorithm throws away some possible subsets, Two questions remain. . .
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
but it always outputs a valid subset (but probably not the largest one)
How big is |L′
i|?
How good is the solution given?
Let Li be the set of sizes of all S′ ⊆ Si which are not larger than t
- L′
i is the trimmed version of Li
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y |S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
For any entry in the original set (Li) . . . there is one in the trimmed set (L′
i) . . .
- f a ‘similar’ size (δ is very small)
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y |S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction)
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1)
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
by the inductive hypothesis
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
So we have that z x y and z
x 1+δ y (1+δ)i
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
So we have that z x y and z
x 1+δ y (1+δ)i
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
So we have that z x y and z
x 1+δ y (1+δ)i
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
So we have that z x y and z
x 1+δ y (1+δ)i
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
So we have that z x y and z
x 1+δ y (1+δ)i
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
So we have that z x y and z
x 1+δ y (1+δ)i
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
So we have that z x y and z
x 1+δ y (1+δ)i
I.e. that there is an z ∈ L′
i with
y (1+δ)i z y as required |S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
So we have that z x y and z
x 1+δ y (1+δ)i
The case that (y − si) ∈ Li−1 is almost identical I.e. that there is an z ∈ L′
i with
y (1+δ)i z y as required |S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
Proof (by induction) Base Case: L0 = L′
0 = {0}
Inductive step: Assume that the lemma holds for (i − 1) As y ∈ Li we have that either y ∈ Li−1 or (y − si) ∈ Li−1 if y ∈ Li−1 then there is a x ∈ L′
i−1 with
y (1+δ)(i−1) x y
By the definition of Trim there is some z ∈ L′
i with z x z · (1 + δ)
So we have that z x y and z
x 1+δ y (1+δ)i
The case that (y − si) ∈ Li−1 is almost identical (we omit it for brevity) I.e. that there is an z ∈ L′
i with
y (1+δ)i z y as required |S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y |S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
By setting i = m and δ = ǫ/2m we have that, For any y ∈ Lm there is a z ∈ L′
m with
y (1 +
ǫ 2m )m z y
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
By setting i = m and δ = ǫ/2m we have that, For any y ∈ Lm there is a z ∈ L′
m with
y (1 +
ǫ 2m )m z y
Further, Opt ∈ Lm meaning there is a z ∈ L′
m with
Opt
- 1 +
ǫ 2m
m z Opt |S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
By setting i = m and δ = ǫ/2m we have that, For any y ∈ Lm there is a z ∈ L′
m with
y (1 +
ǫ 2m )m z y
Further, Opt ∈ Lm meaning there is a z ∈ L′
m with
Opt
- 1 +
ǫ 2m
m z Opt
Recall that the output of the algorithm is the largest number in L′
- m. . .
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
By setting i = m and δ = ǫ/2m we have that, For any y ∈ Lm there is a z ∈ L′
m with
y (1 +
ǫ 2m )m z y
Further, Opt ∈ Lm meaning there is a z ∈ L′
m with
Opt
- 1 +
ǫ 2m
m z Opt
We only need to show that
- 1 +
ǫ 2m
m 1 + ǫ . . .
Recall that the output of the algorithm is the largest number in L′
- m. . .
|S| = m
Li vs. L′
i
Lemma For any y ∈ Li there is an z ∈ L′
i with
y (1+δ)i z y
By setting i = m and δ = ǫ/2m we have that, For any y ∈ Lm there is a z ∈ L′
m with
y (1 +
ǫ 2m )m z y
Further, Opt ∈ Lm meaning there is a z ∈ L′
m with
Opt
- 1 +
ǫ 2m
m z Opt
We only need to show that
- 1 +
ǫ 2m
m 1 + ǫ . . .
Recall that the output of the algorithm is the largest number in L′
- m. . .
|S| = m
VS
Opt 1 + ǫ z Opt
Li vs. L′
i
We need to show that
- 1 +
ǫ 2m
m 1 + ǫ (for 0 < ǫ 1)
|S| = m
Li vs. L′
i
We need to show that
- 1 +
ǫ 2m
m 1 + ǫ (for 0 < ǫ 1)
- 1 + ǫ
2m m eǫ/2 1+ǫ 2+ ǫ 2 2 1+ǫ
|S| = m
Li vs. L′
i
We need to show that
- 1 +
ǫ 2m
m 1 + ǫ (for 0 < ǫ 1)
- 1 + ǫ
2m m eǫ/2 1+ǫ 2+ ǫ 2 2 1+ǫ ex = ∞
i=0 xi i! 1 + x + x2
This follows from the following facts:
ex (1 + x
m )m for all x, m > 0
|S| = m
Li vs. L′
i
We need to show that
- 1 +
ǫ 2m
m 1 + ǫ (for 0 < ǫ 1)
- 1 + ǫ
2m m eǫ/2 1+ǫ 2+ ǫ 2 2 1+ǫ
So the output of the algorithm is some z where,
|S| = m
Li vs. L′
i
We need to show that
- 1 +
ǫ 2m
m 1 + ǫ (for 0 < ǫ 1)
- 1 + ǫ
2m m eǫ/2 1+ǫ 2+ ǫ 2 2 1+ǫ
So the output of the algorithm is some z where,
Opt 1 + ǫ Opt
- 1 +
ǫ 2m
m z Opt |S| = m
Li vs. L′
i
We need to show that
- 1 +
ǫ 2m
m 1 + ǫ (for 0 < ǫ 1)
- 1 + ǫ
2m m eǫ/2 1+ǫ 2+ ǫ 2 2 1+ǫ
So the output of the algorithm is some z where,
Opt 1 + ǫ z Opt |S| = m
Li vs. L′
i
We need to show that
- 1 +
ǫ 2m
m 1 + ǫ (for 0 < ǫ 1)
- 1 + ǫ
2m m eǫ/2 1+ǫ 2+ ǫ 2 2 1+ǫ
So the output of the algorithm is some z where,
But how long does it take to run?
Opt 1 + ǫ z Opt |S| = m
How big is L′ i?
The time complexity depends on |L′
i|. . .
|S| = m
How big is L′ i?
The time complexity depends on |L′
i|. . .
By the definition of Trim we have that, any two successive elements, z, z′ of L′
i have
z′ z 1 + δ = 1 + ǫ 2m
|S| = m
How big is L′ i?
The time complexity depends on |L′
i|. . .
By the definition of Trim we have that, any two successive elements, z, z′ of L′
i have
z′ z 1 + δ = 1 + ǫ 2m
Further, all elements are no greater than t
|S| = m
How big is L′ i?
The time complexity depends on |L′
i|. . .
By the definition of Trim we have that, any two successive elements, z, z′ of L′
i have
z′ z 1 + δ = 1 + ǫ 2m
Further, all elements are no greater than t So L′
i contains at most O(log(1+δ) t) elements
|S| = m
How big is L′ i?
The time complexity depends on |L′
i|. . .
By the definition of Trim we have that, any two successive elements, z, z′ of L′
i have
z′ z 1 + δ = 1 + ǫ 2m
Further, all elements are no greater than t So L′
i contains at most O(log(1+δ) t) elements
log(1+δ) t = ln t ln(1 + (ǫ/2m)) 2m(1 + (ǫ/2m)) ln t ǫ = O m log t ǫ
- |S| = m
How big is L′ i?
The time complexity depends on |L′
i|. . .
By the definition of Trim we have that, any two successive elements, z, z′ of L′
i have
z′ z 1 + δ = 1 + ǫ 2m
Further, all elements are no greater than t So L′
i contains at most O(log(1+δ) t) elements
log(1+δ) t = ln t ln(1 + (ǫ/2m)) 2m(1 + (ǫ/2m)) ln t ǫ = O m log t ǫ
- ln(1 + x) >
x x+1
(here x = ǫ/2m)
another fact:
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i|) time
O(|L′
i|) time
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i|) time
O(|L′
i|) time
As |L′
i| = O(m log t/ǫ), the algorithm runs in
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
O(m2 log t/ǫ) = O(n3 log n/ǫ) time
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i|) time
O(|L′
i|) time
As |L′
i| = O(m log t/ǫ), the algorithm runs in
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
O(m2 log t/ǫ) = O(n3 log n/ǫ) time
|S| = m m n log t = O(n log n)
Recall that n is the length of the input (measured in words)
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i|) time
O(|L′
i|) time
As |L′
i| = O(m log t/ǫ), the algorithm runs in
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
O(m2 log t/ǫ) = O(n3 log n/ǫ) time
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i|) time
O(|L′
i|) time
As |L′
i| = O(m log t/ǫ), the algorithm runs in
The output z is such that
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
O(m2 log t/ǫ) = O(n3 log n/ǫ) time Opt 1 + ǫ z Opt
|S| = m
A PTAS for Subset Sum
The algorithm
- Let L′
0 = {0}, δ = ǫ/(2m)
- For i = 1 . . . m:
- Compute (L′
i−1 + si) from L′ i−1
- Compute U = L′
i−1 ∪ (L′ i−1 + si)
- Output the largest number in L′
m
O(|L′
i−1|) time
O(|L′
i|) time
O(|L′
i|) time
As |L′
i| = O(m log t/ǫ), the algorithm runs in
The output z is such that
- Let L′
i = Trim(U, δ)
O(|L′
m|) time
O(m2 log t/ǫ) = O(n3 log n/ǫ) time Opt 1 + ǫ z Opt
So this is in fact an FPTAS for Subset Sum
|S| = m
Polynomial time approximation schemes
A Polynomial Time Approximation Scheme (PTAS) for problem P is a family of algorithms: For any constant ǫ > 0 there is an algorithm in the family, Aǫ such that Aǫ is a (1 + ǫ)-approximation algorithm for P We have seen an FPTAS for Subset Sum A PTAS does not have to have a time complexity which is polynomial in 1/ǫ A fully PTAS (FPTAS) has a time complexity which is polynomial in 1/ǫ (as well as polynomial in n) i.e. the time complexity is O((n/ǫ)c) for some constant c e.g. the time complexity could be O(n
c ǫ ) (for example)
which runs in O(n3 log n/ǫ) time The output z is such that