Question

In: Advanced Math

2. Suppose you have a collection of n items i1, i2, ..., in with weights w1,...

2. Suppose you have a collection of n items i1, i2, ..., in with weights w1, w2, ..., wn and a bag with capacity W

(a) Describe a simple, efficient algorithm to select as many items as possible to fit inside the bag e.g. the maximum cardinality set of items that have weights that sum to at most W.

(b) Prove your answer.

Solutions

Expert Solution

a) Algorithm:

i) sort in increasing order: ;

ii) set ;

while and ,

if then and

iii) return .

Analsysis: Step i) requires (via Quicksort) steps, and step ii) requires steps. Thus, the time complexity of our algorithm is which shows it is effective (polynomial time).

Note: The design of the algorithm mandates that

b) We need to prove that if is any algorithm and returns , then .

Proof: Suppose, if possible, that . Because of step i), we have

Thus, we have

which is a contradiction. Thus, , completing the proof.


Related Solutions

You have a Delta-neutral portfolio of options and underlying stocks with Gamma I1 and Vega I2....
You have a Delta-neutral portfolio of options and underlying stocks with Gamma I1 and Vega I2. You can trade two options. The first option has Delta, Gamma and Vega, respectively, of .5, .6 and 1.5. The second option has Delta, Gamma and Vega, respectively, of .4, .7 and 2.5. Determine your hedging strategy to make your portfolio neutral for Delta, Gamma and Vega. 30.   How many numbers of the first option will you trade? 31.   How many units of the...
Suppose you have N items with values xi from which we want to sample n items...
Suppose you have N items with values xi from which we want to sample n items with replacement. Each item has its own probability pi of being selected across all times we pick items. What's the estimated variance of the Horvitz-Thompson estimator of T? Let T = > 1, 1=1
Suppose you have N items with values xi from which we want to sample n items...
Suppose you have N items with values xi from which we want to sample n items with replacement. Each item has its own probability pi of being selected across all times we pick items. What's the bias for the following estimator of T: Let T = > 1, 1=1
You have a collection of unique items which all implementComparable. The items need to be...
You have a collection of unique items which all implement Comparable. The items need to be kept sorted at all times. It is important that the items can be queried for as fast as possible. Which Collection is most suitable?TreeMapHashSetTreeSetHashMap
Tigers have weights that are N(500, 20 ). ( pounds ) You win 2 tigers. Find...
Tigers have weights that are N(500, 20 ). ( pounds ) You win 2 tigers. Find the probability that your tigers have an average weight that is more that 510 pounds . Make a 95% confidence interval for the percentage of fish that swim backward in an hour given that you watched 500 fish swim backward for an hour and 100 of these fish swam backwards.
Let W be a subspace of R^n and suppose that v1,v2,w1,w2,w3 are vectors in W. Suppose...
Let W be a subspace of R^n and suppose that v1,v2,w1,w2,w3 are vectors in W. Suppose that v1; v2 are linearly independent and that w1;w2;w3 span W. (a) If dimW = 3 prove that there is a vector in W that is not equal to a linear combination of v1 and v2. (b) If w3 is a linear combination of w1 and w2 prove that w1 and w2 span W. (c) If w3 is a linear combination of w1 and...
Birth weights. Suppose an investigator takes a random sample of n = 50 birth weights from...
Birth weights. Suppose an investigator takes a random sample of n = 50 birth weights from several teaching hospitals located in an inner-city neighborhood. In her random sample, the sample mean x is 3,150 grams and the standard deviation is 250 grams. (a) Calculate a 95% confidence interval for the population mean birth weight in these hospitals. (b) The typical weight of a baby at birth for the US population is 3,250 grams. The investigator suspects that the birth weights...
, we are given a set of n items. Each item weights between 0 and 1....
, we are given a set of n items. Each item weights between 0 and 1. We also have a set of bins (knapsacks). Each bin has a capacity of 1, i.e., total weight in any bin should be less than 1. The problem is to pack the items into as few bins as possible. For example Given items: 0.2, 0.5, 0.4, 0.7, 0.1, 0.3, 0.8 Opt Solution: Bin1[0.2, 0.8], Bin2[0.5, 0.4, 0.1], Bin3[0.7, 0.3] Each item must be placed...
Suppose that the distribution of the weights of bags of carrots from brand A is N(1.2,0.049)...
Suppose that the distribution of the weights of bags of carrots from brand A is N(1.2,0.049) and the distribution of the weights of bags of carrots from brand A is N(3.5, 0.081). The weights of bags from two brands is independent. Selecting bags at random find a) The probability that the sum of a random sample of the weights of three bags from brand A exceeds the weight of a bag from brand B. Give answer to the 4th decimal....
Suppose the following data are product weights for the same items produced on two different production...
Suppose the following data are product weights for the same items produced on two different production lines. Line 1 Line 2 13.6 13.4 13.9 14.2 14.0 14.5 13.8 14.0 13.1 14.6 13.5 13.7 13.3 14.1 13.6 14.9 12.8 14.7 14.1 14.3 15.0 14.8 Test for a difference between the product weights for the two lines. Use α = 0.05. State the null and alternative hypotheses. H0: Median for line 1 − Median for line 2 ≥ 0 Ha: Median for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT