Download - Approximation Algorithms Part Three: (F)PTAS
Advanced Algorithms – COMS31900
Approximation algorithms part three
(Fully) Polynomial Time Approximation Schemes
Benjamin Sach
Approximation Algorithms Recap
An algorithmA 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α 6 s 6 Opt
within an α factor of Opt
• If P is a minimisation problem, Opt 6 s 6 α ·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 47
322
t = 12
The Subset Sum problem
4 47
322
t = 12
• Let S be a multi-set of positive integers and t be a positive integer
|S| = m
The Subset Sum problem
4 47
322
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 47
322
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 47
322
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
732
• 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 42
• 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 42
• 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 47
322
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 47
322
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 47
322
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
722
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
722
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 theoptimisation problem is ‘11’
The Subset Sum problem
4 47
322
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 47
322
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 47
322
S
S3
|S| = m
An exact solution
Let S = {s1, s2, s3 . . . sm} be the set of items and Si = {s1, s2, . . . , si}
4 47
322
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 47
322
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}
24
(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}
24 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}
24 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
24 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:
24 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)
24 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 6 t
24 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 6 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 6 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 6 t
7L3 + 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 6 t
2
7L3 + 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 6 t
47
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 6 t
24
7L3 + 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 6 t
74 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 6 t
2
74 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 6 t
24 4
72
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 6 t
24 4
72
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| 6 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| 6 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| 6 t
The overall time complexity is thereforeO(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| 6 t
The overall time complexity is thereforeO(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| 6 t
The overall time complexity is thereforeO(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| 6 t
The overall time complexity is thereforeO(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| 6 t
The overall time complexity is thereforeO(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| 6 t
The overall time complexity is thereforeO(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| 6 t
The overall time complexity is thereforeO(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 ∈ Θ(logn))
|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| 6 t
The overall time complexity is thereforeO(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| 6 t
The overall time complexity is thereforeO(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| 6 t
The overall time complexity is thereforeO(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| 6 t
The overall time complexity is thereforeO(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
Asm 6 n, the time isO(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| 6 t
The overall time complexity is thereforeO(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
Asm 6 n, the time isO(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| 6 t
The overall time complexity is thereforeO(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
Asm 6 n, the time isO(nt) . . . but t could be (for example) 2n
|S| = m
. . . in other wordsO(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 6 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 6 nc
for some constant c
The algorithm for Subset Sum given takesO(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 6 nc
for some constant c
The algorithm for Subset Sum given takesO(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 6 nc
for some constant c
The algorithm for Subset Sum given takesO(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 6 nc
for some constant c
The algorithm for Subset Sum given takesO(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 6 nc
for some constant c
The algorithm for Subset Sum given takesO(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 6 nc
for some constant c
The algorithm for Subset Sum given takesO(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 6 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 6 nc
for some constant c
The algorithm for Subset Sum given takesO(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 6 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 6 nc
for some constant c
The algorithm for Subset Sum given takesO(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 6 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 6 nc
for some constant c
The algorithm for Subset Sum given takesO(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 6 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 thatAε 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 thatAε 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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.01 so thatA0.01 also runs in polynomial time and
outputs a subset of size at least Opt1.01 > 0.99 ·Opt
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.01 so thatA0.01 also runs in polynomial time and
outputs a subset of size at least Opt1.01 > 0.99 ·Opt
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.1 > 0.9 ·Opt
Let ε = 0.001 so thatA0.001 also runs in polynomial time and
outputs a subset of size at least Opt1.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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 ofO(ncε ) 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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 ofO(ncε ) 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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 isO((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 thatAε is a (1 + ε)-approximation algorithm for P
• If we had a PTAS for Subset Sum we could:
Let ε = 0.1 so thatA0.1 runs in polynomial time and
outputs a subset of size at least Opt1.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 isO((n/ε)c) for some constant c
In our exampleO((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 247
(here t = 12)
42
47
4
47
2
4
42
7
4
A PTAS for Subset Sum
The exact algorithm for Subset Sum was slow (in general) becauseeach 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 247
(here t = 12)
42
47
4
47
2
4
42
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| 6 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| 6 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| 6 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| 6 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 42
47
4
47
2
4
42
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| 6 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 42
47
4
47
2
4
42
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| 6 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 42
47
4
47
2
4
42
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| 6 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| 6 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| 6 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| 6 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
24
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
24
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
24
L′i−1 = si = 3
2
(L′i−1 + si) =
U = L′i−1 ∪ (L′i−1 + si) =2
242
3 4
33
32
|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
24
L′i−1 = si = 3
2
(L′i−1 + si) =
U = L′i−1 ∪ (L′i−1 + si) =2
242
3
= L′i = Trim(U, δ)
2(with δ = 1)
4
33
32
23
|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
24
L′i−1 = si = 3
2
(L′i−1 + si) =
U = L′i−1 ∪ (L′i−1 + si) =2
242
3
= L′i = Trim(U, δ)
2(with δ = 1)
4
33
3
keep each thing if it is more than (1 + δ)
times as big as the last thing you kept
2
23
|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 withy
(1+δ)i6 z 6 y
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 y
For any entry in the original set (Li) . . .
there is one in the trimmed set (L′i) . . .
of a ‘similar’ size (δ is very small)
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 y
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 y
Proof (by induction)
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)i6 z 6 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 withy
(1+δ)i6 z 6 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 withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
by the inductive hypothesis
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
So we have that z 6 x 6 y and z > x1+δ > y
(1+δ)i
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
So we have that z 6 x 6 y and z > x1+δ > y
(1+δ)i
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
So we have that z 6 x 6 y and z > x1+δ > y
(1+δ)i
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
So we have that z 6 x 6 y and z > x1+δ > y
(1+δ)i
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
So we have that z 6 x 6 y and z > x1+δ > y
(1+δ)i
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
So we have that z 6 x 6 y and z > x1+δ > y
(1+δ)i
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
So we have that z 6 x 6 y and z > x1+δ > y
(1+δ)i
I.e. that there is an z ∈ L′i withy
(1+δ)i6 z 6 y as required
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
So we have that z 6 x 6 y and z > x1+δ > y
(1+δ)i
The case that (y − si) ∈ Li−1 is almost identical
I.e. that there is an z ∈ L′i withy
(1+δ)i6 z 6 y as required
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 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 withy
(1+δ)(i−1) 6 x 6 y
By the definition of Trim there is some z ∈ L′i with z 6 x 6 z · (1 + δ)
So we have that z 6 x 6 y and z > x1+δ > 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 withy
(1+δ)i6 z 6 y as required
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 y
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 y
By setting i = m and δ = ε/2m we have that,
For any y ∈ Lm there is a z ∈ L′m withy
(1 + ε2m )m
6 z 6 y
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 y
By setting i = m and δ = ε/2m we have that,
For any y ∈ Lm there is a z ∈ L′m withy
(1 + ε2m )m
6 z 6 y
Further, Opt ∈ Lm meaning there is a z ∈ L′m with
Opt(1 + ε
2m
)m 6 z 6 Opt
|S| = m
Li vs. L′i
Lemma For any y ∈ Li there is an z ∈ L′i withy
(1+δ)i6 z 6 y
By setting i = m and δ = ε/2m we have that,
For any y ∈ Lm there is a z ∈ L′m withy
(1 + ε2m )m
6 z 6 y
Further, Opt ∈ Lm meaning there is a z ∈ L′m with
Opt(1 + ε
2m
)m 6 z 6 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 withy
(1+δ)i6 z 6 y
By setting i = m and δ = ε/2m we have that,
For any y ∈ Lm there is a z ∈ L′m withy
(1 + ε2m )m
6 z 6 y
Further, Opt ∈ Lm meaning there is a z ∈ L′m with
Opt(1 + ε
2m
)m 6 z 6 Opt
We only need to show that(1 + ε
2m
)m 6 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 withy
(1+δ)i6 z 6 y
By setting i = m and δ = ε/2m we have that,
For any y ∈ Lm there is a z ∈ L′m withy
(1 + ε2m )m
6 z 6 y
Further, Opt ∈ Lm meaning there is a z ∈ L′m with
Opt(1 + ε
2m
)m 6 z 6 Opt
We only need to show that(1 + ε
2m
)m 6 1 + ε . . .
Recall that the output of the algorithm is the largest number in L′m. . .
|S| = m
VSOpt
1 + ε6 z 6 Opt
Li vs. L′i
We need to show that(1 + ε
2m
)m 6 1 + ε (for 0 < ε 6 1)
|S| = m
Li vs. L′i
We need to show that(1 + ε
2m
)m 6 1 + ε (for 0 < ε 6 1)
(1 +
ε
2m
)m6 eε/2 6 1+
ε
2+( ε2
)2
6 1+ε
|S| = m
Li vs. L′i
We need to show that(1 + ε
2m
)m 6 1 + ε (for 0 < ε 6 1)
(1 +
ε
2m
)m6 eε/2 6 1+
ε
2+( ε2
)2
6 1+ε
ex =∑∞
i=0xi
i!6 1 + x+ x2
This follows from the following facts:
ex > (1 + xm )m for all x,m > 0
|S| = m
Li vs. L′i
We need to show that(1 + ε
2m
)m 6 1 + ε (for 0 < ε 6 1)
(1 +
ε
2m
)m6 eε/2 6 1+
ε
2+( ε2
)2
6 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 6 1 + ε (for 0 < ε 6 1)
(1 +
ε
2m
)m6 eε/2 6 1+
ε
2+( ε2
)2
6 1+ε
So the output of the algorithm is some z where,
Opt
1 + ε6
Opt(1 + ε
2m
)m 6 z 6 Opt
|S| = m
Li vs. L′i
We need to show that(1 + ε
2m
)m 6 1 + ε (for 0 < ε 6 1)
(1 +
ε
2m
)m6 eε/2 6 1+
ε
2+( ε2
)2
6 1+ε
So the output of the algorithm is some z where,
Opt
1 + ε6 z 6 Opt
|S| = m
Li vs. L′i
We need to show that(1 + ε
2m
)m 6 1 + ε (for 0 < ε 6 1)
(1 +
ε
2m
)m6 eε/2 6 1+
ε
2+( ε2
)2
6 1+ε
So the output of the algorithm is some z where,
But how long does it take to run?
Opt
1 + ε6 z 6 Opt
|S| = m
How big isL′i?
The time complexity depends on |L′i|. . .
|S| = m
How big isL′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 isL′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 isL′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 mostO(log(1+δ) t) elements
|S| = m
How big isL′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 mostO(log(1+δ) t) elements
log(1+δ) t =ln t
ln(1 + (ε/2m))6
2m(1 + (ε/2m)) ln t
ε= O
(m log t
ε
)
|S| = m
How big isL′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 mostO(log(1+δ) t) elements
log(1+δ) t =ln t
ln(1 + (ε/2m))6
2m(1 + (ε/2m)) ln t
ε= O
(m log t
ε
)
ln(1 + x) > xx+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 logn/ε) 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 logn/ε) time
|S| = m
m 6 nlog t = O(n logn)
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 logn/ε) 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 logn/ε) time
Opt
1 + ε6 z 6 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 logn/ε) time
Opt
1 + ε6 z 6 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 thatAε 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 isO((n/ε)c) for some constant c
e.g. the time complexity could beO(ncε ) (for example)
which runs inO(n3 logn/ε) time
The output z is such thatOpt
1 + ε6 z 6 Opt