SlideServe
Menu
Préférences
© SlideServe · v2026

Knapsack Problem: Greedy vs. Brute Force

fruma avatar
16 diapositives · 1K Views · Apr 15, 2012

Knapsack Problem: Greedy vs. Brute Force. pp 313-317 (Section 7.6). Greedy Approach. To solve problems you have to make decisions. At each decision point, you pick the greedy (or best) option. i.e., make an optimal move given what you know For some problems a greed strategy

Knapsack Problem: Greedy vs. Brute Force - slide 1
01 / 16Knapsack Problem: Greedy vs. Brute Force
1 / 17

Télécharger la présentation

Knapsack Problem: Greedy vs. Brute Force
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Knapsack Problem: Greedy vs. Brute Force pp 313-317 (Section 7.6)

  2. Greedy Approach • To solve problems you have to make decisions. • At each decision point, you pick the greedy (or best) option. • i.e., make an optimal move given what you know • For some problems a greed strategy • produces an optimal solution • produces a very bad solution

  3. Continuous Knapsack Problem • Continuous Knapsack Variation • Input: N chapters • Goal: Maximize importance • Constraint: Report must be 600 pages

  4. Continuous Knapsack Problem Step 1: Pick the chapter with the most importance (Chapter 4). Maximize the importance by choosing all 150 pages

  5. Continuous Knapsack Problem Step 2: Greedy choice… pick the most important remaining chapter:Chapter 1 and 2 are tied, pick both, i.e., 270 pages Report (600 pages max):All of Chapter 4 (importance 8)450 pages leftTotal Importance = 8

  6. Continuous Knapsack Problem Step 3: Greedy choice… pick Chapter 3.However, we can only pick 90% of it, i.e., 180 out of 200 pages. Report (600 pages max):All of Chapter 4 (importance 8)All of Chapter 1 (importance 5)All of Chapter 2 (importance 5)180 pages leftTotal Importance = 8 + 5 + 5

  7. Continuous Knapsack Problem Is the final answer optimal? Can you pick page differently and beat 21.6? Report (600 pages max):All of Chapter 4 (importance 8)All of Chapter 1 (importance 5)All of Chapter 2 (importance 5)90% of Chapter 3 (importance 4)0 pages leftTotal Importance = 8 + 5 + 5 + 4*0.9 = 21.6

  8. Constrained Optimization Problems • Many different real-world problem can be reduced to constrained optimization problems. • Some factor needs to be maximized or minimized (Goal) • Real-world constraints limit the choices you can make (Constraints)

  9. Constrained Optimization Problems • Examples: • Package routing • Input: N packages and N delivery points • Goal: Minimize the package delivery time • Constrains: X number of trucks • CPU allocation • Input: N processing jobs each with a priority • Goal: Maximize total priority throughput • Constaints: X processor, Y memory, Z time

  10. Non-Continuous Knapsack Problem • Greedy approach does NOT work. • Just call it the Knapsack Problem • Constraint: Sack holds 100 lbs. • Goal: Maximize sack value • Input: Packages

  11. Greedy: Lowest Weight First 79 lbs $83

  12. Greedy: Lowest Weight Firstwith one Backtracking step 79 lbs $83-------------------------- 21 lbs remaining26 lbs $30 item avail. removing the lowest valued item 5 lbs. or more.---------------------------95 lbs $103

  13. Greedy: Highest Value First 99 lbs $100

  14. Greedy: Highest Value Firstwith one Restart step 99 lbs $100---------------------Skip the most valuable item and start again---------------------98 lbs $107

  15. Greedy: Highest Density 90 lbs $103

  16. Greedy: Highest Densitywith one Backtracking step 90 lbs $103------------------10 lbs remaining15 lbs $10 item avail. removing the lowest valued item 5 lbs. or more.---------------------------96 lbs $102