In class, we discussed two different algorithms for the maximum subsequence problem (one brute force; the other more sophisticated that runs in O(n) time).
Here's a third algorithm. For each element i of the sequence 1, 2, ..., n, compute the value of the largest contiguous subsequence (segment is simpler and which is what I shall use) that ends at i. This can be done in one traversal from the left to the right. At the same time, record the starting index of this maximum segment sum, and the end index i (obviously!).
Once this is done, in another left-to-right scan, one can determine the largest segment sum and the start and end indices of this segment.
The following example for a sequence of 10 integers might help in understanding the problem better.
index: 0 1 2 3 4 6 8 9
sequence: -99 94 -96 12 99 41 -4 -62 -29 50
start index: -1 1 -1 3 3 3 3 3 3 3
segment sum: 0 94 0 12 111 152 148 86 57 107
For a set of 10 randomly generated sequences, each consisting of 15 integers, print the value of a maximum subsequence that you obtain, as well as the start index and the end index of this maximum subsequence. There can be several; it's enough to report one. (10 points)