Knapsack Problem: Greedy vs. Brute Force pp 313-317 (Section 7.6)

Slides:



Advertisements
Similar presentations
 Review: The Greedy Method
Advertisements

MCS 312: NP Completeness and Approximation algorithms Instructor Neelima Gupta
Greedy Algorithms.
Knapsack Problem Section 7.6. Problem Suppose we have n items U={u 1,..u n }, that we would like to insert into a knapsack of size C. Each item u i has.
Algorithm Design Techniques: Greedy Algorithms. Introduction Algorithm Design Techniques –Design of algorithms –Algorithms commonly used to solve problems.
Chapter 5 Fundamental Algorithm Design Techniques.
Analysis of Algorithms
5-1 Chapter 5 Tree Searching Strategies. 5-2 Satisfiability problem Tree representation of 8 assignments. If there are n variables x 1, x 2, …,x n, then.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 7: Greedy Algorithms
Cs333/cutler Greedy1 Introduction to Greedy Algorithms The greedy technique Problems explored –The coin changing problem –Activity selection.
Merge Sort 4/15/2017 6:09 PM The Greedy Method The Greedy Method.
Branch and bound Pasi Fränti Explore all alternatives Solution constructed by stepwise choices Decision tree Guarantees optimal solution Exponential.
Identifying "Good" Architectural Design Alternatives with Multi-Objective Optimization Strategies By Lars Grunske Presented by Robert Dannels.
0-1 Knapsack Problem A burglar breaks into a museum and finds “n” items Let v_i denote the value of ith item, and let w_i denote the weight of the ith.
© 5/7/2002 V.S. Subrahmanian1 Knapsack Problem Notes V.S. Subrahmanian University of Maryland.
© 5/7/2002 V.S. Subrahmanian1 Knapsack Problem Notes V.S. Subrahmanian University of Maryland.
KNAPSACK PROBLEM A dynamic approach. Knapsack Problem  Given a sack, able to hold K kg  Given a list of objects  Each has a weight and a value  Try.
Week 2: Greedy Algorithms
Dynamic Programming 0-1 Knapsack These notes are taken from the notes by Dr. Steve Goddard at
1 The Greedy Method CSC401 – Analysis of Algorithms Lecture Notes 10 The Greedy Method Objectives Introduce the Greedy Method Use the greedy method to.
The Knapsack Problem Input –Capacity K –n items with weights w i and values v i Goal –Output a set of items S such that the sum of weights of items in.
Dave Risch. Project Specifications There is a “knapsack” that you want to fill with the most valuable items that are available to you. Each item has a.
Bold Stroke January 13, 2003 Advanced Algorithms CS 539/441 OR In Search Of Efficient General Solutions Joe Hoffert
1 1 Slide © 2000 South-Western College Publishing/ITP Slides Prepared by JOHN LOUCKS.
CSC 413/513: Intro to Algorithms Greedy Algorithms.
5-1-1 CSC401 – Analysis of Algorithms Chapter 5--1 The Greedy Method Objectives Introduce the Brute Force method and the Greedy Method Compare the solutions.
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
Topic 25 Dynamic Programming "Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it.
The Greedy Method. The Greedy Method Technique The greedy method is a general algorithm design paradigm, built on the following elements: configurations:
CSC 201: Design and Analysis of Algorithms Greedy Algorithms.
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
Hunter Gear Optimization Team Alt + F4 Michael Barbour; Joshua Law son; Michael Lee.
Algorithm Design Methods 황승원 Fall 2011 CSE, POSTECH.
Backtracking & Brute Force Optimization Intro2CS – weeks
Dynamic Programming … Continued 0-1 Knapsack Problem.
Math for Liberal Studies.  The knapsack problem is a variation of the bin packing problems we have been discussing  This time, there is just one bin.
Spring 2008The Greedy Method1. Spring 2008The Greedy Method2 Outline and Reading The Greedy Method Technique (§5.1) Fractional Knapsack Problem (§5.1.1)
CS 361 – Chapter 10 “Greedy algorithms” It’s a strategy of solving some problems –Need to make a series of choices –Each choice is made to maximize current.
A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 18.
Greedy Algorithms Prof. Kharat P. V. Department of Information Technology.
Introduction to Algorithms: Brute-Force Algorithms.
Greedy Algorithms Alexandra Stefan.
Greedy Method 6/22/2018 6:57 PM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.
Algorithm Design Methods
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
The Greedy Method and Text Compression
Robbing a House with Greedy Algorithms
The Greedy Method and Text Compression
The Knapsack Problem.
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
The Greedy Method Spring 2007 The Greedy Method Merge Sort
Merge Sort 11/28/2018 2:21 AM The Greedy Method The Greedy Method.
Merge Sort 11/28/2018 8:16 AM The Greedy Method The Greedy Method.
Brute Force Approaches
Exam 2 LZW not on syllabus. 73% / 75%.
Analysis & Design of Algorithms (CSCE 321)
Advanced Algorithms Analysis and Design
Greedy Algorithms.
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Greedy Algorithms Alexandra Stefan.
Planning and Scheduling
Not guaranteed to find best answer, but run in a reasonable time
Algorithm Design Methods
Lecture 6 Greedy Algorithms
Algorithm Design Methods
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Title Page.
Knapsack Problem A dynamic approach.
Algorithm Design Methods
Presentation transcript:

Knapsack Problem: Greedy vs. Brute Force pp (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 –produces an optimal solution –produces a very bad solution

Continuous Knapsack Problem Continuous Knapsack Variation –Input: N chapters –Goal: Maximize importance –Constraint: Report must be 600 pages ChapterPagesImportance

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

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 ChapterPagesImportance Report (600 pages max): All of Chapter 4 (importance 8) 450 pages left Total Importance = 8

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. ChapterPagesImportance Report (600 pages max): All of Chapter 4 (importance 8) All of Chapter 1 (importance 5) All of Chapter 2 (importance 5) 180 pages left Total Importance =

Continuous Knapsack Problem Is the final answer optimal? Can you pick page differently and beat 21.6? ChapterPagesImportance 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 left Total Importance = *0.9 = 21.6

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)

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

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 ItemWeightValue A3 lbs$4 B4 lbs$8 C9 lbs$11 D10 lbs$10 E13 lbs$15 F15 lbs$10 G25 lbs$25 H26 lbs$30 I50 lbs$51 J55 lbs$54 K60 lbs$55

ItemWeightValue Density A3$ B4$ C9$ D10$ E13$ F15$ G25$ H26$ I50$ J55$ K60$ lbs $83 Greedy: Lowest Weight First

ItemWeightValue Density A3$ B4$ C9$ D10$ E13$ F15$ G25$ H26$ I50$ J55$ K60$ lbs $ lbs remaining 26 lbs $30 item avail. removing the lowest valued item 5 lbs. or more lbs $103 Greedy: Lowest Weight First with one Backtracking step

99 lbs $100 Greedy: Highest Value First ItemWeightValue Density K60$ J55$ I50$ H26$ G25$25 1 E13$ C9$ D10$10 1 F15$ B4$8 2 A3$4 1.33

99 lbs $ Skip the most valuable item and start again lbs $107 Greedy: Highest Value First with one Restart step ItemWeightValue Density K60$ J55$ I50$ H26$ G25$25 1 E13$ C9$ D10$10 1 F15$ B4$8 2 A3$4 1.33

90 lbs $103 Greedy: Highest Density ItemWeightValue Density B4$8 2 A3$ C9$ H26$ E13$ I50$ G25$25 1 D10$10 1 J55$ K60$ F15$

90 lbs $ lbs remaining 15 lbs $10 item avail. removing the lowest valued item 5 lbs. or more lbs $102 Greedy: Highest Density with one Backtracking step ItemWeightValue Density B4$8 2 A3$ C9$ H26$ E13$ I50$ G25$25 1 D10$10 1 J55$ K60$ F15$