Question: Write a JAVA application that prints largest contiguous sum based on recursion using following procedures: - Use this method to return maximum contiguous sum: public

Write a JAVA application that prints largest contiguous sum based on recursion using following procedures:

- Use this method to return maximum contiguous sum:

public static int maxSum (int[] list)

- The maxSum method acts as surrogate method that calls another method (recursive method) which does the actual work:

public static int maxContiguousSum (int[] list, int start, int end)

- Use a base case that contains just one element.

- Assume we can determine the maximum sum for a list of contiguous items in a shorter list. (Looking ahead: the shorter list that well use in the next step, the general case, will be the list beginning at cell start+1 and ending at cell end (you could also do start till end-1). Well remember that sum as it will be a candidate for the maximum sum that our method should return.

- General case: From our assumption we know what the maximum contiguous sum is for all cells excluding the first cell, so now we need to consider any sum, which contains the first cell. So now compute (use a loop, not recursion here) all possible sums from your list that include the first cell. As you compute these sums compare them to your maximum sum so far (which initially will be what was returned by your assumption above).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!