Write a recursive method that will find and return the largest value in an array of integers. Hint: Split the array in half and recursively find the largest value in each half. Return the larger of those two values.

What will be an ideal response?

```
public static int max(int [] data){
return max(data, 0, data.length-1);
}

public static int max(int [] data, int first, int last){
int result;

if(first == last)
result = data[first]; // only one value in the subarray
else{
int mid = (last + first)/2;
int max1 = max(data, first, mid);
int max2 = max(data, mid+1, last);
if(max1 > max2)
result = max1;
else
result = max2;
}

return result;

}
```

This code is in Methods.java..

Computer Science & Information Technology

You might also like to view...

After you create a gradient swatch from pink to yellow, you apply it to a frame. The gradient spans from left to right, and you want to make it span top to bottom. What can you do?

What will be an ideal response?

Computer Science & Information Technology

A blade server chassis has two power supplies. Which of the following is a benefit of a technician connecting each power supply to a separate UPS unit?

A. Quality of service B. Fault tolerance C. Traffic shaping D. Load balancing

Computer Science & Information Technology