02-greedy

# Prove that the provided making change algorithm is

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: ptimal for denominations 1, 6, and 10 Via induction, and on board --&gt; 14 Knapsack Algorithm 15 Knapsack Problems Inputs: n items, each with a weight wi and a value vi capacity of the knapsack, C Output: Fractions for each of the n items, xi Chosen to maximize total profit but not to exceed knapsack capacity 16 Two Types of Knapsack Problem 0/1 knapsack problem Greedy approach does not produce optimal solutions Each item is discrete. Must choose all of it or none of it. So each xi is 0 or 1 But another approach, dynamic programming, does Continuous knapsack problem Can pick up fractions of each item The correct selection function yields a greedy algorithm that produces optimal results 17 Greedy Rule for Knapsack? Build up a partial solution by choosing xi for one item until knapsack is full (or no more items). Which item to choose? There are several choices. Pick one and try on this: n = 3, C = 20 weights = (18, 15, 10) values = (25, 24, 15) What answer do you get? The optimal answer is: (0, 1, 0.5), total=31.5 18 Can you verify this? Possible Greedy Rules for Kn...
View Full Document

Ask a homework question - tutors are online