161
Advanced Algorithms – COMS31900 Approximation algorithms part three (Fully) Polynomial Time Approximation Schemes Benjamin Sach

Approximation Algorithms Part Three: (F)PTAS

Embed Size (px)

Citation preview

Page 1: Approximation Algorithms Part Three: (F)PTAS

Advanced Algorithms – COMS31900

Approximation algorithms part three

(Fully) Polynomial Time Approximation Schemes

Benjamin Sach

Page 2: Approximation Algorithms Part Three: (F)PTAS

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

Page 3: Approximation Algorithms Part Three: (F)PTAS

The Subset Sum problem

4 47

322

t = 12

Page 4: Approximation Algorithms Part Three: (F)PTAS

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

Page 5: Approximation Algorithms Part Three: (F)PTAS

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

Page 6: Approximation Algorithms Part Three: (F)PTAS

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

Page 7: Approximation Algorithms Part Three: (F)PTAS

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

Page 8: Approximation Algorithms Part Three: (F)PTAS

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

Page 9: Approximation Algorithms Part Three: (F)PTAS

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

Page 10: Approximation Algorithms Part Three: (F)PTAS

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

Page 11: Approximation Algorithms Part Three: (F)PTAS

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

Page 12: Approximation Algorithms Part Three: (F)PTAS

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

Page 13: Approximation Algorithms Part Three: (F)PTAS

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

Page 14: Approximation Algorithms Part Three: (F)PTAS

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

Page 15: Approximation Algorithms Part Three: (F)PTAS

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’

Page 16: Approximation Algorithms Part Three: (F)PTAS

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

Page 17: Approximation Algorithms Part Three: (F)PTAS

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

Page 18: Approximation Algorithms Part Three: (F)PTAS

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

Page 19: Approximation Algorithms Part Three: (F)PTAS

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

Page 20: Approximation Algorithms Part Three: (F)PTAS

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

Page 21: Approximation Algorithms Part Three: (F)PTAS

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

Page 22: Approximation Algorithms Part Three: (F)PTAS

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

Page 23: Approximation Algorithms Part Three: (F)PTAS

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

Page 24: Approximation Algorithms Part Three: (F)PTAS

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

Page 25: Approximation Algorithms Part Three: (F)PTAS

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

Page 26: Approximation Algorithms Part Three: (F)PTAS

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

Page 27: Approximation Algorithms Part Three: (F)PTAS

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

Page 28: Approximation Algorithms Part Three: (F)PTAS

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

Page 29: Approximation Algorithms Part Three: (F)PTAS

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

Page 30: Approximation Algorithms Part Three: (F)PTAS

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

Page 31: Approximation Algorithms Part Three: (F)PTAS

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

Page 32: Approximation Algorithms Part Three: (F)PTAS

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

Page 33: Approximation Algorithms Part Three: (F)PTAS

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

Page 34: Approximation Algorithms Part Three: (F)PTAS

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

Page 35: Approximation Algorithms Part Three: (F)PTAS

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

Page 36: Approximation Algorithms Part Three: (F)PTAS

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

Page 37: Approximation Algorithms Part Three: (F)PTAS

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

Page 38: Approximation Algorithms Part Three: (F)PTAS

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

Page 39: Approximation Algorithms Part Three: (F)PTAS

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

Page 40: Approximation Algorithms Part Three: (F)PTAS

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

Page 41: Approximation Algorithms Part Three: (F)PTAS

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

Page 42: Approximation Algorithms Part Three: (F)PTAS

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

Page 43: Approximation Algorithms Part Three: (F)PTAS

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

Page 44: Approximation Algorithms Part Three: (F)PTAS

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

Page 45: Approximation Algorithms Part Three: (F)PTAS

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

Page 46: Approximation Algorithms Part Three: (F)PTAS

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

Page 47: Approximation Algorithms Part Three: (F)PTAS

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

Page 48: Approximation Algorithms Part Three: (F)PTAS

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

Page 49: Approximation Algorithms Part Three: (F)PTAS

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

Page 50: Approximation Algorithms Part Three: (F)PTAS

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

Page 51: Approximation Algorithms Part Three: (F)PTAS

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

Page 52: Approximation Algorithms Part Three: (F)PTAS

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

Page 53: Approximation Algorithms Part Three: (F)PTAS

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

Page 54: Approximation Algorithms Part Three: (F)PTAS

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

Page 55: Approximation Algorithms Part Three: (F)PTAS

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

Page 56: Approximation Algorithms Part Three: (F)PTAS

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

Page 57: Approximation Algorithms Part Three: (F)PTAS

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

Page 58: Approximation Algorithms Part Three: (F)PTAS

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

Page 59: Approximation Algorithms Part Three: (F)PTAS

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

Page 60: Approximation Algorithms Part Three: (F)PTAS

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!

Page 61: Approximation Algorithms Part Three: (F)PTAS

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

Page 62: Approximation Algorithms Part Three: (F)PTAS

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)

Page 63: Approximation Algorithms Part Three: (F)PTAS

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

Page 64: Approximation Algorithms Part Three: (F)PTAS

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

Page 65: Approximation Algorithms Part Three: (F)PTAS

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

Page 66: Approximation Algorithms Part Three: (F)PTAS

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

Page 67: Approximation Algorithms Part Three: (F)PTAS

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

Page 68: Approximation Algorithms Part Three: (F)PTAS

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

Page 69: Approximation Algorithms Part Three: (F)PTAS

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)

Page 70: Approximation Algorithms Part Three: (F)PTAS

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)

Page 71: Approximation Algorithms Part Three: (F)PTAS

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

Page 72: Approximation Algorithms Part Three: (F)PTAS

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:

Page 73: Approximation Algorithms Part Three: (F)PTAS

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

Page 74: Approximation Algorithms Part Three: (F)PTAS

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

Page 75: Approximation Algorithms Part Three: (F)PTAS

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

Page 76: Approximation Algorithms Part Three: (F)PTAS

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

Page 77: Approximation Algorithms Part Three: (F)PTAS

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/ε

Page 78: Approximation Algorithms Part Three: (F)PTAS

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

Page 79: Approximation Algorithms Part Three: (F)PTAS

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

Page 80: Approximation Algorithms Part Three: (F)PTAS

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/ε

Page 81: Approximation Algorithms Part Three: (F)PTAS

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)

Page 82: Approximation Algorithms Part Three: (F)PTAS

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

Page 83: Approximation Algorithms Part Three: (F)PTAS

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

Page 84: Approximation Algorithms Part Three: (F)PTAS

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

Page 85: Approximation Algorithms Part Three: (F)PTAS

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

Page 86: Approximation Algorithms Part Three: (F)PTAS

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)

Page 87: Approximation Algorithms Part Three: (F)PTAS

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)

Page 88: Approximation Algorithms Part Three: (F)PTAS

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)

Page 89: Approximation Algorithms Part Three: (F)PTAS

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)

Page 90: Approximation Algorithms Part Three: (F)PTAS

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

Page 91: Approximation Algorithms Part Three: (F)PTAS

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

Page 92: Approximation Algorithms Part Three: (F)PTAS

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

Page 93: Approximation Algorithms Part Three: (F)PTAS

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

Page 94: Approximation Algorithms Part Three: (F)PTAS

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

Page 95: Approximation Algorithms Part Three: (F)PTAS

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. . .

Page 96: Approximation Algorithms Part Three: (F)PTAS

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)

Page 97: Approximation Algorithms Part Three: (F)PTAS

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)

Page 98: Approximation Algorithms Part Three: (F)PTAS

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

Page 99: Approximation Algorithms Part Three: (F)PTAS

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

Page 100: Approximation Algorithms Part Three: (F)PTAS

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

Page 101: Approximation Algorithms Part Three: (F)PTAS

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

Page 102: Approximation Algorithms Part Three: (F)PTAS

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

Page 103: Approximation Algorithms Part Three: (F)PTAS

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

Page 104: Approximation Algorithms Part Three: (F)PTAS

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

Page 105: Approximation Algorithms Part Three: (F)PTAS

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

Page 106: Approximation Algorithms Part Three: (F)PTAS

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

Page 107: Approximation Algorithms Part Three: (F)PTAS

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

Page 108: Approximation Algorithms Part Three: (F)PTAS

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

Page 109: Approximation Algorithms Part Three: (F)PTAS

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

Page 110: Approximation Algorithms Part Three: (F)PTAS

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

Page 111: Approximation Algorithms Part Three: (F)PTAS

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

Page 112: Approximation Algorithms Part Three: (F)PTAS

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

Page 113: Approximation Algorithms Part Three: (F)PTAS

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

Page 114: Approximation Algorithms Part Three: (F)PTAS

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

Page 115: Approximation Algorithms Part Three: (F)PTAS

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

Page 116: Approximation Algorithms Part Three: (F)PTAS

Li vs. L′i

Lemma For any y ∈ Li there is an z ∈ L′i withy

(1+δ)i6 z 6 y

|S| = m

Page 117: Approximation Algorithms Part Three: (F)PTAS

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

Page 118: Approximation Algorithms Part Three: (F)PTAS

Li vs. L′i

Lemma For any y ∈ Li there is an z ∈ L′i withy

(1+δ)i6 z 6 y

|S| = m

Page 119: Approximation Algorithms Part Three: (F)PTAS

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

Page 120: Approximation Algorithms Part Three: (F)PTAS

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

Page 121: Approximation Algorithms Part Three: (F)PTAS

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

Page 122: Approximation Algorithms Part Three: (F)PTAS

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

Page 123: Approximation Algorithms Part Three: (F)PTAS

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

Page 124: Approximation Algorithms Part Three: (F)PTAS

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

Page 125: Approximation Algorithms Part Three: (F)PTAS

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

Page 126: Approximation Algorithms Part Three: (F)PTAS

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

Page 127: Approximation Algorithms Part Three: (F)PTAS

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

Page 128: Approximation Algorithms Part Three: (F)PTAS

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

Page 129: Approximation Algorithms Part Three: (F)PTAS

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

Page 130: Approximation Algorithms Part Three: (F)PTAS

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

Page 131: Approximation Algorithms Part Three: (F)PTAS

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

Page 132: Approximation Algorithms Part Three: (F)PTAS

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

Page 133: Approximation Algorithms Part Three: (F)PTAS

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

Page 134: Approximation Algorithms Part Three: (F)PTAS

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

Page 135: Approximation Algorithms Part Three: (F)PTAS

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

Page 136: Approximation Algorithms Part Three: (F)PTAS

Li vs. L′i

Lemma For any y ∈ Li there is an z ∈ L′i withy

(1+δ)i6 z 6 y

|S| = m

Page 137: Approximation Algorithms Part Three: (F)PTAS

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

Page 138: Approximation Algorithms Part Three: (F)PTAS

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

Page 139: Approximation Algorithms Part Three: (F)PTAS

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

Page 140: Approximation Algorithms Part Three: (F)PTAS

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

Page 141: Approximation Algorithms Part Three: (F)PTAS

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

Page 142: Approximation Algorithms Part Three: (F)PTAS

Li vs. L′i

We need to show that(1 + ε

2m

)m 6 1 + ε (for 0 < ε 6 1)

|S| = m

Page 143: Approximation Algorithms Part Three: (F)PTAS

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

Page 144: Approximation Algorithms Part Three: (F)PTAS

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

Page 145: Approximation Algorithms Part Three: (F)PTAS

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

Page 146: Approximation Algorithms Part Three: (F)PTAS

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

Page 147: Approximation Algorithms Part Three: (F)PTAS

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

Page 148: Approximation Algorithms Part Three: (F)PTAS

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

Page 149: Approximation Algorithms Part Three: (F)PTAS

How big isL′i?

The time complexity depends on |L′i|. . .

|S| = m

Page 150: Approximation Algorithms Part Three: (F)PTAS

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

Page 151: Approximation Algorithms Part Three: (F)PTAS

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

Page 152: Approximation Algorithms Part Three: (F)PTAS

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

Page 153: Approximation Algorithms Part Three: (F)PTAS

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

Page 154: Approximation Algorithms Part Three: (F)PTAS

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

Page 155: Approximation Algorithms Part Three: (F)PTAS

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

Page 156: Approximation Algorithms Part Three: (F)PTAS

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

Page 157: Approximation Algorithms Part Three: (F)PTAS

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)

Page 158: Approximation Algorithms Part Three: (F)PTAS

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

Page 159: Approximation Algorithms Part Three: (F)PTAS

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

Page 160: Approximation Algorithms Part Three: (F)PTAS

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

Page 161: Approximation Algorithms Part Three: (F)PTAS

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