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...

According to the BSIMM, what practice typically has the highest maturity level among top organizations?

A. Code review B. Training C. Compliance and policy D. Security testing

Computer Science & Information Technology

What are the advantages and limitations of autonomous access points?

What will be an ideal response?

Computer Science & Information Technology

In what ways does input validation improve the quality of data stored in a database?

What will be an ideal response?

Computer Science & Information Technology

What are two advantages to working in Outline view for a presentation?

What will be an ideal response?

Computer Science & Information Technology