Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

(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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

What is the relation of physical mathematics with examples?

Answered: 1 week ago

Question

What are oxidation and reduction reactions? Explain with examples

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago