# Approximation Algorithms Part Three: (F)PTAS

date post

14-Apr-2017Category

## Education

view

23download

0

Embed Size (px)

### Transcript of 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 integerhere 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 integerhere 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 integerhere 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

aS a

|S| = m

The Subset Sum problem

t = 12

4

4

2

732

Decision Problem Is there a subset, S S with size t?the size of S is

aS a

|S| = m

The Subset Sum problem

t = 12

7

3

2

4 42

Decision Problem Is there a subset, S S with size t?the size of S is

aS a

|S| = m

The Subset Sum problem

t = 12

7

3

2

4 42

Decision Problem Is there a subset, S S with size t?the size of S is

aS a

|S| = m

The Subset Sum problem

4 47

322

t = 12

Decision Problem Is there a subset, S S with size t?the size of S is

aS a

|S| = m

The Subset Sum problem

4 47

322

t = 12

Decision Problem Is there a subset, S S with size t?

Optimisation Problem

the size of S isaS 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

Decision Problem Is there a subset, S S with size t?

Optimisation Problem

the size of S isaS 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

Decision Problem Is there a subset, S S with size t?

Optimisation Problem

the size of S isaS 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

Decision Problem Is there a subset, S S with size t?

Optimisation Problem

the size of S isaS 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

Decision Problem Is there a subset, S S with size t?

Optimisation Problem

the size of S isaS 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

Decision Problem Is there a subset, S S with size t?

Optimisation Problem

the size of S isaS 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 Li1:

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 Li1: Li = Li1 (Li1 + 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 Li1: Li = Li1 (Li1 + si)

where (x+ si) (Li1 + si) iff x Li1 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 dont 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

|S| = m

An exact solution

The algorithm

Let L0 = {0} For i = 1 . . .m: Compute (Li1 + si) from Li1 Compute Li = Li1 (Li1 + 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) time

|S| = m

An exact solution

The algorithm

Let L0 = {0} For i = 1 . . .m: Compute (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) time

O(|Li|) time

|S| = m

An exact solution

The algorithm

Let L0 = {0} For i = 1 . . .m: Compute (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) time

O(|Li|) time

O(|Lm|) time

|S| = m

An exact solution

The algorithm

Let L0 = {0} For i = 1 . . .m: Compute (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 (Li1 + si) from Li1 Compute Li = Li1 (Li1 + si)

Output the largest number in Lm

O(1) time

O(|Li1|) 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 Li 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 Li Li) so that

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

For every y Li, there is a z Li which is almost as big

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

For every y Li, there is a z Li which is almost as big

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li Li)

Consider this process called Trim. . . Trim(Li, ): Include Li[j] in Li iff

where prev is the previous

Li[j] > (1 + ) prev

entry we included in 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

For every y Li, there is a z Li which is almost as big

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li Li)

Consider this process called Trim. . . Trim(Li, ): Include Li[j] in Li 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 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

For every y Li, there is a z Li which is almost as big

for = 1. . . L4 = {0, 2, 6}

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li Li)

Consider this process called Trim. . . Trim(Li, ): Include Li[j] in Li 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 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

For every y Li, there is a z Li which is almost as big

for = 1. . . L4 = {0, 2, 6}

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li Li)

Consider this process called Trim. . . Trim(Li, ): Include Li[j] in Li 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 Li

L4 is a small subset of L4 and for any y L4,there is an z L4 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

For every y Li, there is a z Li which is almost as big

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li Li)

Consider this process called Trim. . . Trim(Li, ): Include Li[j] in Li iff

where prev is the previous

Li[j] > (1 + ) prev

entry we included in 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

For every y Li, there is a z Li which is almost as big

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li Li)

Consider this process called Trim. . . Trim(Li, ): Include Li[j] in Li iff

where prev is the previous

Li[j] > (1 + ) prev

entry we included in Li

Unfortunately, this hasnt 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

For every y Li, there is a z Li which is almost as big

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li Li)

Consider this process called Trim. . . Trim(Li, ): Include Li[j] in Li iff

where prev is the previous

Li[j] > (1 + ) prev

entry we included in Li

Unfortunately, this hasnt really achieved anything. . .

we dont 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 Li Li) so that

The length of Li is polynomial in the input length (i.e. |Li| 6 n

c for some c)

For every y Li, there is a z Li which is almost as big

(where Si = {s1, s2, . . . , si} - the first i numbers in the input)

Li is a subset of Li (i.e. Li Li)

Consider this process called Trim. . . Trim(Li, ): Include Li[j] in Li iff

where prev is the previous

Li[j] > (1 + ) prev

entry we included in Li

Unfortunately, this hasnt really achieved anything. . .

we dont 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 L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

Trim(U, ): Include U [j] in Li iff U [j] > (1 + ) prevwhere prev is the previous thing we included in Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

2

24

Li1 = si = 3

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

2

24

Li1 = si = 3

2

(Li1 + si) =3

3

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

2

24

Li1 = si = 3

2

(Li1 + si) =

U = Li1 (Li1 + si) =

2

242

3 4

33

32

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

2

24

Li1 = si = 3

2

(Li1 + si) =

U = Li1 (Li1 + si) =

2

242

3

= Li = Trim(U, )2

(with = 1)

4

33

32

23

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

2

24

Li1 = si = 3

2

(Li1 + si) =

U = Li1 (Li1 + si) =

2

242

3

= Li = 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 L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li1|) time

Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li1|) time

O(|Li|) time Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li1|) time

O(|Li|) time Let Li = Trim(U, )

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

Trim(U, ): Include U [j] in Li iff U [j] > (1 + ) prevwhere prev is the previous thing we included in Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li1|) time

O(|Li|) time Let Li = Trim(U, )

O(|Lm|) time

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

Trim(U, ): Include U [j] in Li iff U [j] > (1 + ) prevwhere prev is the previous thing we included in Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li1|) time

O(|Li|) time Let Li = Trim(U, )

O(|Lm|) time

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li1|) time

O(|Li|) time

This algorithm throws away some possible subsets,

Let Li = Trim(U, )

O(|Lm|) 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

- Li is the trimmed version of Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li1|) time

O(|Li|) time

This algorithm throws away some possible subsets,

Two questions remain. . .

Let Li = Trim(U, )

O(|Lm|) 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

- Li is the trimmed version of Li

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li1|) time

O(|Li|) time

This algorithm throws away some possible subsets,

Two questions remain. . .

Let Li = Trim(U, )

O(|Lm|) time

but it always outputs a valid subset (but probably not the largest one)

How big is |Li|? How good is the solution given?

Let Li be the set of sizes of all S Si which are not larger than t

- Li is the trimmed version of Li

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

For any entry in the original set (Li) . . .

there is one in the trimmed set (Li) . . .

of a similar size ( is very small)

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

by the inductive hypothesis

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li with z 6 x 6 z (1 + )

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li 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. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li 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. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li 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. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li 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. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li 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. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li 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. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li 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 Li withy

(1+)i6 z 6 y as required

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li 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) Li1 is almost identical

I.e. that there is an z Li withy

(1+)i6 z 6 y as required

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

Proof (by induction)

Base Case: L0 = L0 = {0}

Inductive step: Assume that the lemma holds for (i 1)

As y Li we have that either y Li1 or (y si) Li1

if y Li1 then there is a x Li1 withy

(1+)(i1)6 x 6 y

By the definition of Trim there is some z Li 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) Li1 is almost identical (we omit it for brevity)

I.e. that there is an z Li withy

(1+)i6 z 6 y as required

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

By setting i = m and = /2m we have that,

For any y Lm there is a z Lm withy

(1 + 2m )m

6 z 6 y

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

By setting i = m and = /2m we have that,

For any y Lm there is a z Lm withy

(1 + 2m )m

6 z 6 y

Further, Opt Lm meaning there is a z Lm with

Opt(1 + 2m

)m 6 z 6 Opt

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

By setting i = m and = /2m we have that,

For any y Lm there is a z Lm withy

(1 + 2m )m

6 z 6 y

Further, Opt Lm meaning there is a z Lm with

Opt(1 + 2m

)m 6 z 6 OptRecall that the output of the algorithm is the largest number in Lm. . .

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

By setting i = m and = /2m we have that,

For any y Lm there is a z Lm withy

(1 + 2m )m

6 z 6 y

Further, Opt Lm meaning there is a z Lm 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 Lm. . .

|S| = m

Li vs. Li

Lemma For any y Li there is an z Li withy

(1+)i6 z 6 y

By setting i = m and = /2m we have that,

For any y Lm there is a z Lm withy

(1 + 2m )m

6 z 6 y

Further, Opt Lm meaning there is a z Lm 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 Lm. . .

|S| = m

VSOpt

1 + 6 z 6 Opt

Li vs. Li

We need to show that(1 + 2m

)m 6 1 + (for 0 < 6 1)|S| = m

Li vs. Li

We need to show that(1 + 2m

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

2m

)m6 e/2 6 1+

2+( 2

)26 1+

|S| = m

Li vs. Li

We need to show that(1 + 2m

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

2m

)m6 e/2 6 1+

2+( 2

)26 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. Li

We need to show that(1 + 2m

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

2m

)m6 e/2 6 1+

2+( 2

)26 1+

So the output of the algorithm is some z where,

|S| = m

Li vs. Li

We need to show that(1 + 2m

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

2m

)m6 e/2 6 1+

2+( 2

)26 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. Li

We need to show that(1 + 2m

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

2m

)m6 e/2 6 1+

2+( 2

)26 1+

So the output of the algorithm is some z where,

Opt

1 + 6 z 6 Opt

|S| = m

Li vs. Li

We need to show that(1 + 2m

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

2m

)m6 e/2 6 1+

2+( 2

)26 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 isLi?

The time complexity depends on |Li|. . .

|S| = m

How big isLi?

The time complexity depends on |Li|. . .

By the definition of Trim we have that,

any two successive elements, z, z of Li have

z

z > 1 + = 1 +

2m

|S| = m

How big isLi?

The time complexity depends on |Li|. . .

By the definition of Trim we have that,

any two successive elements, z, z of Li have

z

z > 1 + = 1 +

2m

Further, all elements are no greater than t

|S| = m

How big isLi?

The time complexity depends on |Li|. . .

By the definition of Trim we have that,

any two successive elements, z, z of Li have

z

z > 1 + = 1 +

2m

Further, all elements are no greater than t

So Li contains at mostO(log(1+) t) elements

|S| = m

How big isLi?

The time complexity depends on |Li|. . .

By the definition of Trim we have that,

any two successive elements, z, z of Li have

z

z > 1 + = 1 +

2m

Further, all elements are no greater than t

So Li 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 isLi?

The time complexity depends on |Li|. . .

By the definition of Trim we have that,

any two successive elements, z, z of Li have

z

z > 1 + = 1 +

2m

Further, all elements are no greater than t

So Li 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 L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li|) time

O(|Li|) time Let Li = Trim(U, )

O(|Lm|) time

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li|) time

O(|Li|) time

As |Li| = O(m log t/), the algorithm runs in

Let Li = Trim(U, )

O(|Lm|) time

O(m2 log t/) = O(n3 logn/) time

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li|) time

O(|Li|) time

As |Li| = O(m log t/), the algorithm runs in

Let Li = Trim(U, )

O(|Lm|) 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 L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li|) time

O(|Li|) time

As |Li| = O(m log t/), the algorithm runs in

Let Li = Trim(U, )

O(|Lm|) time

O(m2 log t/) = O(n3 logn/) time

|S| = m

A PTAS for Subset Sum

The algorithm

Let L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li|) time

O(|Li|) time

As |Li| = O(m log t/), the algorithm runs in

The output z is such that

Let Li = Trim(U, )

O(|Lm|) 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 L0 = {0}, = /(2m) For i = 1 . . .m: Compute (Li1 + si) from L

i1

Compute U = Li1 (Li1 + si)

Output the largest number in Lm

O(|Li1|) time

O(|Li|) time

O(|Li|) time

As |Li| = O(m log t/), the algorithm runs in

The output z is such that

Let Li = Trim(U, )

O(|Lm|) 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