Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to write a java programming method that uses a divide-and-conquer strategy to find the maximum value in an integer array. The maximum value

I need to write a java programming method that uses a divide-and-conquer strategy to find the maximum value in an integer array. The maximum value of a one-element array is that element. The maximum of any other array is the maximum of the left half, or the maximum of the right half, whichever is larger. (You can use ArraySum as a starting point.)

And ArraySum is:

public class ArraySum { public static void main(String[] args) { int[] test = {3, 4, 5, 1, 2, 3, 2}; // sum should be 20 int result = arraySum(test); System.out.println(result); } public static int arraySum(int[] arr) { return arraySumRec(arr, 0, arr.length - 1); } private static int arraySumRec(int[] arr, int start, int end) { if (start == end) { return arr[start]; } else { int mid = (start + end) / 2; int leftSum = arraySumRec(arr, start, mid); int rightSum = arraySumRec(arr, mid + 1, end); return leftSum + rightSum; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

4.1 Explain multiple uses of job analysis in HR decisions.

Answered: 1 week ago