In this exercise we will develop a dynamic programming

Chapter 10, Problem 56E

(choose chapter or problem)

In this exercise we will develop a dynamic programming algorithm for finding the maximum sum of consecutive terms of a sequence of real numbers. That is, given a sequence of real numbers \(a_{1}, a_{2}, \ldots, a_{n}\), the algorithm computes the maximum sum \(\sum_{i=j}^{k} a_{i}\) where \(1 \leq j \leq k \leq n\).

a) Show that if all terms of the sequence are nonnegative, this problem is solved by taking the sum of all terms. Then, give an example where the maximum sum of consecutive terms is not the sum of all terms.

b) Let \(M(k)\) be the maximum of the sums of consecutive terms of the sequence ending at \(a_{k}\). That is, \(M(k)=\max _{1 \leq j \leq k} \sum_{i=j}^{k} a_{i}\). Explain why the recurrence relation \(M(k)=\max \left(M(k-1)+a_{k}, a_{k}\right)\) holds for \(k=2, \ldots, n\)

c) Use part (b) to develop a dynamic programming algorithm for solving this problem.

d) Show each step your algorithm from part (c) uses to find the maximum sum of consecutive terms of the sequence \(2,-3,4,1,-2,3\).

e) Show that the worst-case complexity in terms of the number of additions and comparisons of your algorithm from part (c) is linear.

Equation Transcription:

 

Text Transcription:

a_1,a_2,,a_n

sum_i=j^k  a_i

1 < or = j < or = k  < or =n

k= 2,,n

M(k)=maxM(k−1)+a_k,a_k

Unfortunately, we don't have that question answered yet. But you can get it answered in just 5 hours by Logging in or Becoming a subscriber.

Becoming a subscriber
Or look for another answer

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back