Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There is a row of n items, numbered from 1 to n. Each item has an integer value: item i has value A[i], where A[1...n]

There is a row of n items, numbered from 1 to n. Each item has an integer

value: item i has value A[i], where A[1...n] is an array. You wish to pick some

of the items but you cannot pick two adjacent items (that is, you cannot pick

both items i and i + 1 for any i). Subject to this constraint, you wish to

maximise the total sum of values of the items you have picked.

(a) [2 marks] Provide a counterexample to show that it is not always optimal

to pick the largest item.

(b) [3 marks] Provide a counterexample to show that the optimal solution

may require selecting a combination of odd and even numbered elements.

(c) [10 marks] Give an O(n) algorithm that determines this maximum total

sum of values.

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago