Question
You have a long sequence of n items, where each item i has a corresponding weight wi . All weights are positive integers, and a
You have a long sequence of n items, where each item i has a corresponding weight wi . All weights are positive integers, and a weight greater than 50 means that the item is considered heavy. You want to pick up items whose total weight is as large as possible, however: you are picking up the items from left to right (in sequence order), and if you pick up a heavy item then you will be unable to pick up the item immediately after it.
(a) Consider the greedy algorithm that considers the integers from left to right, and picks up each item as long as the rules allow it (either the preceding item was not picked up, or it was not heavy). Give and demonstrate a counterexample to show that this greedy algorithm does not always work.
(b) Design and write (in pseudocode) a dynamic programming algorithm that computes the largest possible total weight allowed from the given input. (if a box is picked, then the next box cannot be picked).
(c) Modify your algorithm from (b) to extract the subsequence that produces the optimum.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started