Question: Maximum Subsequence: The books author talked about the O(N) solution to the maximum subsequence problem and it is implemented such that it only returns the
Maximum Subsequence: The books author talked about the O(N) solution to the maximum subsequence problem and it is implemented such that it only returns the maximum sum. Modify this solution so that it returns an MSPAnswer object, where an MSPAnswer contains:
1) the starting index - i
2) the ending index - j
3) the max sum
................Sample Code........
1
Algorithm Analysis
/** * Linear-time maximum contiguous subsequence sum algorithm.
2 3 */ 4 public static int maxSubSum4( int [ ] a )
5{ 6 int maxSum = 0, thisSum = 0; 7 8 for( int j = 0; j < a.length; j++ )
9{
10 11 12 13 14 15 16 17 18 19 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
