Top Banner
Advanced Algorithms – COMS31900 Approximation algorithms part one Constant factor approximations Benjamin Sach
129

Approximation Algorithms Part One: Constant factor approximations

Apr 13, 2017

Download

Education

Benjamin Sach
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Approximation Algorithms Part One: Constant factor approximations

Advanced Algorithms – COMS31900

Approximation algorithms part one

Constant factor approximations

Benjamin Sach

Page 2: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

(this second part is the definition of NP-hard)

Page 3: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

(this second part is the definition of NP-hard)

‘yes/no’ problems

Page 4: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

(this second part is the definition of NP-hard)

Page 5: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

(this second part is the definition of NP-hard)

we can solveBusingA

Page 6: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

(this second part is the definition of NP-hard)

Page 7: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

If we could solveA quickly we could solve every problem in NP quickly

(this second part is the definition of NP-hard)

Page 8: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

If we could solveA quickly we could solve every problem in NP quickly

They are the ‘hardest’ problems in NP

(this second part is the definition of NP-hard)

Page 9: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

If we could solveA quickly we could solve every problem in NP quickly

They are the ‘hardest’ problems in NP

(this second part is the definition of NP-hard)

that you can’t solve them in polynomial time (i.e. that P 6= NP)Most computer scientists (I’ve met) believe

Page 10: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

If we could solveA quickly we could solve every problem in NP quickly

They are the ‘hardest’ problems in NP

(this second part is the definition of NP-hard)

A polynomial time algorithm for an

NP-complete problem is worth

(a lot more than) a million dollars

Page 11: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

If we could solveA quickly we could solve every problem in NP quickly

They are the ‘hardest’ problems in NP

(this second part is the definition of NP-hard)

Page 12: Approximation Algorithms Part One: Constant factor approximations

NP-completeness recap

A problemA is NP-complete if

NP is the class of decision problems we cancheck the answer to in polynomial time

A is in NP

EveryB in NP has a polynomial time reduction toA

If we could solveA quickly we could solve every problem in NP quickly

They are the ‘hardest’ problems in NP

So if a problem is NP-complete, we give up right?

(this second part is the definition of NP-hard)

Page 13: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

4/8 4/87/8

3/82/82/8

Page 14: Approximation Algorithms Part One: Constant factor approximations

Bin packing

Bins

1

1

4/8 4/87/8

3/82/82/8

Page 15: Approximation Algorithms Part One: Constant factor approximations

Bin packing

Bins

1

Items

1

4/8 4/87/8

3/82/82/8

Page 16: Approximation Algorithms Part One: Constant factor approximations

Bin packing

Bins

1

Items

1

4/8 4/87/8

3/82/82/8

0 < |Item| 6 1

Page 17: Approximation Algorithms Part One: Constant factor approximations

Bin packing

Bins

1

Items

1

4/8 4/87/8

3/82/82/8

0 < |Item| 6 1

I is the sum of all item sizes

Page 18: Approximation Algorithms Part One: Constant factor approximations

Bin packing

Bins

1

Items

1

4/8 4/87/8

3/82/82/8

0 < |Item| 6 1

|Bin| = 1 and there is an unlimited number of bins. . .

I is the sum of all item sizes

Page 19: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

4/8 4/87/8

3/82/82/8

Problem pack all items into the fewest possible bins

Page 20: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

4/8 4/87/8

3/82/82/8

Problem pack all items into the fewest possible bins

This is an example of an optimisation problem

Page 21: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

Problem pack all items into the fewest possible bins

4/8 4/87/8

2/82/8

3/8

This is an example of an optimisation problem

Page 22: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

4/8 4/87/8

3/82/82/8

Problem pack all items into the fewest possible bins

This is an example of an optimisation problem

Page 23: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

Problem pack all items into the fewest possible bins

4/8

4/8

7/8

2/8

2/8

3/8

This is an example of an optimisation problem

Page 24: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

Problem pack all items into the fewest possible bins

4/8

4/8

7/8

2/8

2/8

3/8

Page 25: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

Problem pack all items into the fewest possible bins

4/8

4/8

7/8

2/8

2/8

3/8

The BINPACKING problem is known to be NP-hard

Page 26: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

Problem pack all items into the fewest possible bins

4/8

4/8

7/8

2/8

2/8

3/8

The BINPACKING problem is known to be NP-hard

and the decision version. . . “Can you pack the items into at most k bins?”

is NP-complete

Page 27: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

Problem pack all items into the fewest possible bins

4/8

4/8

7/8

2/8

2/8

3/8

The BINPACKING problem is known to be NP-hard

and the decision version. . . “Can you pack the items into at most k bins?”

is NP-complete

In the decision version,k is part of the input

Page 28: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

Problem pack all items into the fewest possible bins

4/8

4/8

7/8

2/8

2/8

3/8

The BINPACKING problem is known to be NP-hard

Page 29: Approximation Algorithms Part One: Constant factor approximations

Bin packing

1

1

Problem pack all items into the fewest possible bins

4/8

4/8

7/8

2/8

2/8

3/8

The BINPACKING problem is known to be NP-hardbut fortunately we can approximate

Page 30: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/8 4/87/8

3/82/82/8

If item i fits into bin j: pack it, i++; else j++;

Page 31: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/8 4/87/8

3/82/82/8

If item i fits into bin j: pack it, i++; else j++;

Page 32: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/87/8

3/82/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

Page 33: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/87/8

3/82/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

Page 34: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/87/8

3/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

Page 35: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/87/8

3/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

Page 36: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/87/8

3/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

Page 37: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1 7/83/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

4/8

Page 38: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1 7/83/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

4/8

Page 39: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1 7/83/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

4/8

Page 40: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

3/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

4/87/8

Page 41: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

3/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

4/87/8

Page 42: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

3/82/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

4/87/8

Page 43: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

3/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

4/87/8

2/8

Page 44: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

3/8

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

4/87/8

2/8

Page 45: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

If item i fits into bin j: pack it, i++; else j++;

4/8

2/8

4/87/8

2/8

3/8

Page 46: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/8

2/8

4/87/8

2/8

3/8

Page 47: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Page 48: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

where n is the number of items

Page 49: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Page 50: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

and s be the number of non-empty bins (using Next fit)

Page 51: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

Page 52: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

so bs/2c <∑

162i6s

fill(2i− 1) + fill(2i)

Page 53: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

so bs/2c <∑

162i6s

fill(2i− 1) + fill(2i) 6 I

Page 54: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

so bs/2c <∑

162i6s

fill(2i− 1) + fill(2i) 6 I

the sum of theitem weights

Page 55: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

so bs/2c <∑

162i6s

fill(2i− 1) + fill(2i) 6 I 6 Opt

the sum of theitem weights

Page 56: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

so bs/2c <∑

162i6s

fill(2i− 1) + fill(2i) 6 I 6 Opt

the sum of theitem weights

the optimal number of bins

Page 57: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

so bs/2c <∑

162i6s

fill(2i− 1) + fill(2i) 6 I 6 Opt

Page 58: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

so bs/2c <∑

162i6s

fill(2i− 1) + fill(2i) 6 I 6 Opt

therefore s 6 2 ·Opt

Page 59: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

so bs/2c <∑

162i6s

fill(2i− 1) + fill(2i) 6 I 6 Opt

therefore s 6 2 ·Opt in other words the Next Fit is never worse than twice the optimal

Page 60: Approximation Algorithms Part One: Constant factor approximations

Next fit

1

4/8

2/8

4/87/8

2/8

3/8

Next fit runs inO(n) time but how good is it?

Let fill(i) be the sum of item sizes in bin i

Observe that fill(2i− 1) + fill(2i) > 1 (for 1 6 2i 6 s)

and s be the number of non-empty bins (using Next fit)

so bs/2c <∑

162i6s

fill(2i− 1) + fill(2i) 6 I 6 Opt

therefore s 6 2 ·Opt

Page 61: Approximation Algorithms Part One: Constant factor approximations

Approximation Algorithms

An algorithmA is an α-approximation algorithm for problem P if,

◦A runs in polynomial time

◦A always outputs a solution with value s

within an α factor of Opt

Page 62: Approximation Algorithms Part One: Constant factor approximations

Approximation Algorithms

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

within an α factor of Opt

Page 63: Approximation Algorithms Part One: Constant factor approximations

Approximation Algorithms

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

Page 64: Approximation Algorithms Part One: Constant factor approximations

Approximation Algorithms

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 (like BINPACKING), Opt 6 s 6 α ·Opt

Page 65: Approximation Algorithms Part One: Constant factor approximations

Approximation Algorithms

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 (like BINPACKING), Opt 6 s 6 α ·Opt

We have seen a 2-approximation algorithm for BINPACKING

Page 66: Approximation Algorithms Part One: Constant factor approximations

Approximation Algorithms

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 (like BINPACKING), Opt 6 s 6 α ·Opt

We have seen a 2-approximation algorithm for BINPACKING

the number of bins used, s is always between Opt and 2 ·Opt

Page 67: Approximation Algorithms Part One: Constant factor approximations

Approximation Algorithms

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 (like BINPACKING), Opt 6 s 6 α ·Opt

We have seen a 2-approximation algorithm for BINPACKING

the number of bins used, s is always between Opt and 2 ·Opt

In the examples we consider, α will be a constant but it could depend on n (the input size)

Page 68: Approximation Algorithms Part One: Constant factor approximations

1

4/8

2/8

4/87/8

2/8

3/8

We have seen that Next fit is a 2-approximation algorithm for Bin packingwhich runs inO(n) time

can we do better?

Page 69: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

4/8 4/87/8

3/82/82/8

Page 70: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

Step 1: Sort the items into non-increasing order

4/8 4/87/8

3/82/82/8

Page 71: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

4/8 4/87/8

3/8 2/8 2/8

Step 1: Sort the items into non-increasing order

Page 72: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

4/8 4/87/8

3/8 2/8 2/8

Step 2: Put each item in the first (left-most) bin it fits in

Page 73: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

4/8 4/8 3/8 2/8 2/8

Step 2: Put each item in the first (left-most) bin it fits in

7/8

Page 74: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

4/8 3/8 2/8 2/8

Step 2: Put each item in the first (left-most) bin it fits in

7/84/8

Page 75: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

3/8 2/8 2/8

Step 2: Put each item in the first (left-most) bin it fits in

7/84/8

4/8

Page 76: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

2/8 2/8

Step 2: Put each item in the first (left-most) bin it fits in

7/84/8

4/8

3/8

Page 77: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

2/8

Step 2: Put each item in the first (left-most) bin it fits in

7/84/8

4/8

3/8

2/8

Page 78: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

Step 2: Put each item in the first (left-most) bin it fits in

7/84/8

4/8

3/8

2/8

2/8

Page 79: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

Step 2: Put each item in the first (left-most) bin it fits in

7/84/8

4/8

3/8

2/8

2/8

this will be important

for the proof

Page 80: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

Step 2: Put each item in the first (left-most) bin it fits in

7/84/8

4/8

3/8

2/8

2/8

Page 81: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

7/84/8

4/8

3/8

2/8

2/8

Page 82: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1

1

7/84/8

4/8

3/8

2/8

2/8

FFD runs inO(n2) time but how good is it?

Page 83: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

1 7/84/8

4/8

3/8

2/8

2/8

FFD runs inO(n2) time but how good is it?

Page 84: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

ss

Page 85: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

j

ss

Page 86: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

j

ss

Page 87: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 1: Bin j contains an item of size> 1/2

j

ss

Page 88: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 1: Bin j contains an item of size> 1/2

j

ss

Page 89: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 1: Bin j contains an item of size> 1/2

Every bin j′ 6 j contains an item of size> 1/2

j

ss

Page 90: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 1: Bin j contains an item of size> 1/2

Every bin j′ 6 j contains an item of size> 1/2

because we packed big things first and each thing was

packed in the lowest numbered bin

j

ss

Page 91: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 1: Bin j contains an item of size> 1/2

Every bin j′ 6 j contains an item of size> 1/2

because we packed big things first and each thing was

packed in the lowest numbered bin

j

ss

Page 92: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 1: Bin j contains an item of size> 1/2

Every bin j′ 6 j contains an item of size> 1/2

j

ss

Page 93: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 1: Bin j contains an item of size> 1/2

Every bin j′ 6 j contains an item of size> 1/2

each of these items has to be in a different bin (even in Opt)

j

ss

Page 94: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 1: Bin j contains an item of size> 1/2

Every bin j′ 6 j contains an item of size> 1/2

each of these items has to be in a different bin (even in Opt)

So Opt uses at least 2s3 bins

j

ss

Page 95: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 1: Bin j contains an item of size> 1/2

Every bin j′ 6 j contains an item of size> 1/2

each of these items has to be in a different bin (even in Opt)

So Opt uses at least 2s3 bins

or. . .s 63Opt

2

j

ss

Page 96: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

j

ss

Page 97: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

when FFD packed the first item into bin j,

j

ss

Page 98: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

when FFD packed the first item into bin j,

j

ss

Page 99: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

when FFD packed the first item into bin j,

j

ss

Page 100: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

when FFD packed the first item into bin j,

j

1. all bins j, (j + 1), . . . , (s− 2), (s− 1) were empty

ss

Page 101: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

when FFD packed the first item into bin j,

j

1. all bins j, (j + 1), . . . , (s− 2), (s− 1) were empty

ss

2. and all unpacked items had size 6 1/2

(because we pack in non-increasing order)

Page 102: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two items

when FFD packed the first item into bin j,

j

1. all bins j, (j + 1), . . . , (s− 2), (s− 1) were empty

ss

2. and all unpacked items had size 6 1/2

(because we pack in non-increasing order)

Page 103: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two items

when FFD packed the first item into bin j,

j

1. all bins j, (j + 1), . . . , (s− 2), (s− 1) were empty

ss

2. and all unpacked items had size 6 1/2

(because we pack in non-increasing order)

2+ 2+ 2+ 2+

Page 104: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two items

when FFD packed the first item into bin j,

j

1. all bins j, (j + 1), . . . , (s− 2), (s− 1) were empty

ss

2. and all unpacked items had size 6 1/2

(because we pack in non-increasing order)

2+ 2+ 2+ 2+

(we only use a new bin when the item won’t fit in any previous bin)

Page 105: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two items

when FFD packed the first item into bin j,

j

1. all bins j, (j + 1), . . . , (s− 2), (s− 1) were empty

ss

2. and all unpacked items had size 6 1/2

(because we pack in non-increasing order)

2+ 2+ 2+ 2+

Page 106: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

when FFD packed the first item into bin j,

j

1. all bins j, (j + 1), . . . , (s− 2), (s− 1) were empty

ss

2. and all unpacked items had size 6 1/2

(because we pack in non-increasing order)

2+ 2+ 2+ 2+

Page 107: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

when FFD packed the first item into bin j,

j

1. all bins j, (j + 1), . . . , (s− 2), (s− 1) were empty

ss

2. and all unpacked items had size 6 1/2

(because we pack in non-increasing order)

2+ 2+ 2+ 2+ 1+

Page 108: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

j

ss

2+ 2+ 2+ 2+ 1+

Page 109: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

j

ss

2+ 2+ 2+ 2+ 1+

Page 110: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

j

ss

2+ 2+ 2+ 2+ 1+

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 111: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

j

ss

2+ 2+ 2+ 2+ 1+

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 112: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

otherwise we would have packed them there

j

ss

2+ 2+ 2+ 2+ 1+

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 113: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

j

ss

2+ 2+ 2+ 2+ 1+

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 114: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

so I > min{j − 1, 2(s− j) + 1}

j

ss

2+ 2+ 2+ 2+ 1+

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 115: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

so I > min{j − 1, 2(s− j) + 1}recall I is the total weight of all items

j

ss

2+ 2+ 2+ 2+ 1+

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 116: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

so I > min{j − 1, 2(s− j) + 1}recall I is the total weight of all items

pairing these with theseconsiderconsider

j

ss

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 117: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

so I > min{j − 1, 2(s− j) + 1}recall I is the total weight of all items

pairing these with theseconsiderconsider

j

ss

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

this + this> 1

Page 118: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

so I > min{j − 1, 2(s− j) + 1}recall I is the total weight of all items

j

ss

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 119: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

so I > min{j − 1, 2(s− j) + 1}

j

ss

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 120: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

so I > min{j − 1, 2(s− j) + 1}> d2s/3e − 1

j

ss

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 121: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

This gives a total of 2(s− j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)

so I > min{j − 1, 2(s− j) + 1}> d2s/3e − 1

by plugging in j = d2s/3e

j

ss

so Bins j, (j + 1), . . . , (s− 2), (s− 1) each contain at least two itemsand bin s contains at least one item

Page 122: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

As d2s/3e − 1 < I

j

ss

Page 123: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

As d2s/3e − 1 < I and I 6 Opt

j

ss

Page 124: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

As d2s/3e − 1 < I

we have that d2s/3e − 1 < Opt

and I 6 Opt

j

ss

Page 125: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

As d2s/3e − 1 < I

we have that d2s/3e − 1 < Opt

and I 6 Opt

. . . but both sides are integers. . .

so d2s/3e 6 Opt

finally . . .2s/3 6 d2s/3e 6 Opt

or s 6 (3/2)Opt

j

ss

Page 126: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

j

ss

Page 127: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

Case 2: Bin j contains only items of size 6 1/2

Case 1: Bin j contains an item of size> 1/2

in both cases. . .s 63Opt

2

j

ss

Page 128: Approximation Algorithms Part One: Constant factor approximations

First fit decreasing (FFD)

Consider bin j =⌈2s3

⌉(s is the number of bins FFD uses on this input)

So FFD is a 3/2-approximation algorithm for BINPACKING

Case 2: Bin j contains only items of size 6 1/2

Case 1: Bin j contains an item of size> 1/2

in both cases. . .s 63Opt

2

j

ss

Page 129: Approximation Algorithms Part One: Constant factor approximations

Approximation Algorithms Summary

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 (like BINPACKING), Opt 6 s 6 α ·Opt

We have seen Next Fit which is a 2-approximation algorithm for BINPACKING

which runs inO(n) time

and First Fit Decreasing which is a 3/2-approximation algorithm for BINPACKING

which runs inO(n2) time

Bin Packing is NP-hard so solving it exactly in polynomial time would prove that P = NP