Question: A baker must load W cupcakes into n empty boxes. Let {p1, P2, ... Pa} represent the number of cupcakes that can fit in

A baker must load W cupcakes into n empty boxes. Let {p1, P2, ... Pa} represent the number of cupcakes that

A baker must load W cupcakes into n empty boxes. Let {p1, P2, ... Pa} represent the number of cupcakes that can fit in each box (size). 1.Describe a greedy algorithm that, given W and {P1.P2... Pn}, determines the smallest number of boxes required for cupcake packaging. Demonstrate that your algorithm is correct. 2. How do you modify your algorithm if each box also has an associated cost c,, and you wish to reduce the overall cost of the bottles used to hold all of the cupcakes?

Step by Step Solution

3.53 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Part 1 Greedy Algorithm for Minimizing the Number of Boxes Algorithm Sort the array P1 P2 Pn in nondecreasing order Initialize a variable boxes to 0 I... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!