robbing a house with greedy algorithms

83
Robbing a House with Greedy Algorithms Casey O’Brien

Upload: leanna

Post on 22-Feb-2016

40 views

Category:

Documents


0 download

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

TRANSCRIPT

Page 1: Robbing a House with Greedy Algorithms

Robbing a House withGreedy Algorithms

Casey O’Brien

Page 2: Robbing a House with Greedy Algorithms

Knapsack Problem

Page 3: Robbing a House with Greedy Algorithms
Page 4: Robbing a House with Greedy Algorithms

Your Knapsack

Max Weight: 10 pounds

Page 5: Robbing a House with Greedy Algorithms

Item

Page 6: Robbing a House with Greedy Algorithms

Item Value

13

5

3

6

9

Page 7: Robbing a House with Greedy Algorithms

Item Value Weight

13 8

5 5

3 0.6

6 1.5

9 3

Page 8: Robbing a House with Greedy Algorithms

Goal: Maximize total value

Constraint: Total weight cannot exceed

10 pounds

Page 9: Robbing a House with Greedy Algorithms

Item Value Weight

13 8

5 5

3 0.6

6 1.5

9 3

Page 10: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 11: Robbing a House with Greedy Algorithms

Play The Robber!

Page 12: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 13: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 14: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

12 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 15: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 16: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 17: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 18: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $14

Page 19: Robbing a House with Greedy Algorithms

Play The Robber!

Page 20: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 21: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 22: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 23: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 24: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 25: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 26: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 27: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 28: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $19

Page 29: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $16

Page 30: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 31: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 32: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 33: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 34: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 35: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 36: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $14

Page 37: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $20

Page 38: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $17

Page 39: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 40: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 41: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 42: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $15

Page 43: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $18

Page 44: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 45: Robbing a House with Greedy Algorithms

Greedy Algorithms

Page 46: Robbing a House with Greedy Algorithms

Greedy by Largest Value

Page 47: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 48: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 49: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 50: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $19

Page 51: Robbing a House with Greedy Algorithms

Greedy by Smallest Weight

Page 52: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 53: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 54: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 55: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 56: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $18

Page 57: Robbing a House with Greedy Algorithms

Greedy by Largest Ratio

Page 58: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 59: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 60: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 61: Robbing a House with Greedy Algorithms

Item Value Weight Value/Weight

Knapsack

13 8 1.6

5 5 1

3 0.6 5

6 1.5 4

9 3 3

Page 62: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $18

Page 63: Robbing a House with Greedy Algorithms

Problem:Greedy Algorithms do not guarantee optimal

solution

Page 64: Robbing a House with Greedy Algorithms

Exhaustive Enumeration

Page 65: Robbing a House with Greedy Algorithms

Exhaustive Enumeration

Try All Possibilities

Page 66: Robbing a House with Greedy Algorithms

How Many Possibilities?

Page 67: Robbing a House with Greedy Algorithms
Page 68: Robbing a House with Greedy Algorithms
Page 69: Robbing a House with Greedy Algorithms
Page 70: Robbing a House with Greedy Algorithms
Page 71: Robbing a House with Greedy Algorithms
Page 72: Robbing a House with Greedy Algorithms
Page 73: Robbing a House with Greedy Algorithms
Page 74: Robbing a House with Greedy Algorithms
Page 75: Robbing a House with Greedy Algorithms

Final Knapsack:

Final Value: $20

Page 76: Robbing a House with Greedy Algorithms

Problem:Takes Too Long!

Page 77: Robbing a House with Greedy Algorithms

40 Items

Page 78: Robbing a House with Greedy Algorithms

40 Items

~1 Trillion Possibilities

Page 79: Robbing a House with Greedy Algorithms

40 Items

~1 Trillion Possibilities

~35,000 Years to Compute

Page 80: Robbing a House with Greedy Algorithms

What Can We Do?

Page 81: Robbing a House with Greedy Algorithms

Settle For Less Than Optimal

Page 82: Robbing a House with Greedy Algorithms

Recall Greedy Algorithms:

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

Optimal: $20

Page 83: Robbing a House with Greedy Algorithms

Moral of the Story:

We can use Greedy Algorithms to

approximate solutions to the knapsack problem quickly.