Robbing a House with Greedy Algorithms
description
Transcript of Robbing a House with Greedy Algorithms
![Page 1: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/1.jpg)
Robbing a House withGreedy Algorithms
Casey O’Brien
![Page 2: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/2.jpg)
Knapsack Problem
![Page 3: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/3.jpg)
![Page 4: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/4.jpg)
Your Knapsack
Max Weight: 10 pounds
![Page 5: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/5.jpg)
Item
![Page 6: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/6.jpg)
Item Value
13
5
3
6
9
![Page 7: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/7.jpg)
Item Value Weight
13 8
5 5
3 0.6
6 1.5
9 3
![Page 8: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/8.jpg)
Goal: Maximize total value
Constraint: Total weight cannot exceed
10 pounds
![Page 9: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/9.jpg)
Item Value Weight
13 8
5 5
3 0.6
6 1.5
9 3
![Page 10: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/11.jpg)
Play The Robber!
![Page 12: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/12.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/13.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/15.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/16.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/17.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/18.jpg)
Final Knapsack:
Final Value: $14
![Page 19: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/19.jpg)
Play The Robber!
![Page 20: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/20.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/21.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/22.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/23.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/24.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/25.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/26.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/27.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/28.jpg)
Final Knapsack:
Final Value: $19
![Page 29: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/29.jpg)
Final Knapsack:
Final Value: $16
![Page 30: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/30.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/31.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/32.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/33.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/34.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/35.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/36.jpg)
Final Knapsack:
Final Value: $14
![Page 37: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/37.jpg)
Final Knapsack:
Final Value: $20
![Page 38: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/38.jpg)
Final Knapsack:
Final Value: $17
![Page 39: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/39.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/40.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/41.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/42.jpg)
Final Knapsack:
Final Value: $15
![Page 43: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/43.jpg)
Final Knapsack:
Final Value: $18
![Page 44: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/44.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/45.jpg)
Greedy Algorithms
![Page 46: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/46.jpg)
Greedy by Largest Value
![Page 47: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/47.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/48.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/49.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/50.jpg)
Final Knapsack:
Final Value: $19
![Page 51: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/51.jpg)
Greedy by Smallest Weight
![Page 52: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/52.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/53.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/54.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/55.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/56.jpg)
Final Knapsack:
Final Value: $18
![Page 57: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/57.jpg)
Greedy by Largest Ratio
![Page 58: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/58.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/59.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/60.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/61.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/62.jpg)
Final Knapsack:
Final Value: $18
![Page 63: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/63.jpg)
Problem:Greedy Algorithms do not guarantee optimal
solution
![Page 64: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/64.jpg)
Exhaustive Enumeration
![Page 65: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/65.jpg)
Exhaustive Enumeration
Try All Possibilities
![Page 66: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/66.jpg)
How Many Possibilities?
![Page 67: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/67.jpg)
![Page 68: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/68.jpg)
![Page 69: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/69.jpg)
![Page 70: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/70.jpg)
![Page 71: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/71.jpg)
![Page 72: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/72.jpg)
![Page 73: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/73.jpg)
![Page 74: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/74.jpg)
![Page 75: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/75.jpg)
Final Knapsack:
Final Value: $20
![Page 76: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/76.jpg)
Problem:Takes Too Long!
![Page 77: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/77.jpg)
40 Items
![Page 78: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/78.jpg)
40 Items
~1 Trillion Possibilities
![Page 79: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/79.jpg)
40 Items
~1 Trillion Possibilities
~35,000 Years to Compute
![Page 80: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/80.jpg)
What Can We Do?
![Page 81: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/81.jpg)
Settle For Less Than Optimal
![Page 82: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/82.jpg)
Recall Greedy Algorithms:
By Value: $19By Weight: $18By Ratio: $18
Optimal: $20
![Page 83: Robbing a House with Greedy Algorithms](https://reader036.fdocuments.in/reader036/viewer/2022062501/56816181550346895dd11318/html5/thumbnails/83.jpg)
Moral of the Story:
We can use Greedy Algorithms to
approximate solutions to the knapsack problem quickly.