Robbing a House with Greedy Algorithms

Preview:

DESCRIPTION

Robbing a House with Greedy Algorithms. Casey O’Brien. Knapsack Problem. Your Knapsack Max Weight: 10 pounds. Goal: Maximize total value Constraint: Total weight cannot exceed 10 pounds. Play The Robber!. Final Knapsack: Final Value: $14. Play The Robber!. Final Knapsack: - PowerPoint PPT Presentation

Citation preview

Robbing a House withGreedy Algorithms

Casey O’Brien

Knapsack Problem

Your Knapsack

Max Weight: 10 pounds

Item

Item Value

13

5

3

6

9

Item Value Weight

13 8

5 5

3 0.6

6 1.5

9 3

Goal: Maximize total value

Constraint: Total weight cannot exceed

10 pounds

Item Value Weight

13 8

5 5

3 0.6

6 1.5

9 3

Item Value Weight Value/Weight

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Play The Robber!

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

12 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Final Knapsack:

Final Value: $14

Play The Robber!

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Final Knapsack:

Final Value: $19

Final Knapsack:

Final Value: $16

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Final Knapsack:

Final Value: $14

Final Knapsack:

Final Value: $20

Final Knapsack:

Final Value: $17

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Final Knapsack:

Final Value: $15

Final Knapsack:

Final Value: $18

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Greedy Algorithms

Greedy by Largest Value

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Final Knapsack:

Final Value: $19

Greedy by Smallest Weight

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Final Knapsack:

Final Value: $18

Greedy by Largest Ratio

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Final Knapsack:

Final Value: $18

Problem:Greedy Algorithms do not guarantee optimal

solution

Exhaustive Enumeration

Exhaustive Enumeration

Try All Possibilities

How Many Possibilities?

Final Knapsack:

Final Value: $20

Problem:Takes Too Long!

40 Items

40 Items

~1 Trillion Possibilities

40 Items

~1 Trillion Possibilities

~35,000 Years to Compute

What Can We Do?

Settle For Less Than Optimal

Recall Greedy Algorithms:

By Value: $19By Weight: $18By Ratio: $18

Optimal: $20

Moral of the Story:

We can use Greedy Algorithms to

approximate solutions to the knapsack problem quickly.

Recommended