This exercise deals with the problem offinding the largest

Chapter 7, Problem 7.3.23

(choose chapter or problem)

This exercise deals with the problem offinding the largest sum of consecutive terms of a sequence of n real numbers. When all terms are positive, the sum of all terms provides the answer, but the situation is more complicated when some terms are negative. For example, the maximum sum of consecutive terms of the sequence -2, 3, - 1, 6, -7, 4 is 3 + (- 1) + 6 = 8. (This exercise is based on [Be86].) a) Use pseudocode to describe an algorithm that solves this problem by finding the sums of consecutive terms starting with the first term, the sums of consecutive terms starting with the second term, and so on, keeping track of the maximum sum found so far as the algorithm proceeds. b) Determine the computational complexity of the algorithm in part (a) in terms of the number of sums computed and the number of comparisons made. c) Devise a divide-and-conquer algorithm to solve this problem. [Hint: Assume that there are an even number ofterms in the sequence and split the sequence into two halves. Explain how to handle the case when the maximum sum of consecutive terms includes terms in both halves.] d) Use the algorithm from part (c) to find the maximum sum of consecutive terms of each of the sequences: -2, 4, -1, 3, 5, -6, 1 , 2;4, 1 , -3, 7, -1,-5, 3, -2; and -1, 6, 3, -4, -5, 8, -1, 7. e) Find a recurrence relation for the number of sums and comparisons used by the divide-and-conquer algorithm from part (c). 1) Use the Master Theorem to estimate the computational complexity of the divide-and-conquer algorithm. How does it compare in terms of computational complexity with the algorithm from part (a)?

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