{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture topic-BruteForce

# Maximum design and analysis of algorithms chapter 3

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ck problem a Given a knapsack with maximum capacity W, and Given and a set S consisting of n items a Each item i has some weight wi and benefit value vi Each a Problem: How to pack the knapsack to achieve How maximum total value of packed items? maximum Design and Analysis of Algorithms – Chapter 3 51 0-1 Knapsack problem: a picture Weight vi 2 3 3 4 4 5 8 9 This is a knapsack Max weight: W = 20 wi 5 Items W = 20 Benefit value 10 Design and Analysis of Algorithms – Chapter 3 52 0-1 Knapsack problem a Problem, in other words, is to find max ∑ vi subject to i∈T a a ∑w ≤W i∈T i The problem is called a “0-1” problem, problem, because each item must be entirely accepted or rejected. rejected. In the “Fractional Knapsack Problem,” we can ,” take fractions of items. Design and Analysis of Algorithms – Chapter 3 53 0-1 Knapsack problem: brute-force 0-1 approach approach Let’s first solve this problem with a Let’s straightforward algorithm straightforward a We go through all combinations (subsets) and We find the one with maximum value and with total weight less or equal to W Design and Analysis of Algorithms – Chapter 3 54 Example 2: Knapsack Problem Given n items: Given • weights: w1 w2 … wn weights: • values: v1 v2 … vn values: • a knapsack of capacity W knapsac...
View Full Document

{[ snackBarMessage ]}