Question: Consider the following data field and method. Method maxHelper is intended to return the largest value among the first numVals values in an array; however,

Consider the following data field and method. Method maxHelper is intended to return the largest value among the first numVals values in an array; however, maxHelper does not work as intended.
private int[] nums;
// precondition: 0< numVals <= nums.length
private int maxHelper(int numVals)
{
Line 1: int max = maxHelper(numVals -1);
Line 2: if (max > nums[numVals -1])
return max;
else
return nums[numVals -1];
}
Which of the following best describes the conditions under which maxHelper does not work as intended?
Responses
When numVals is 1
When numVals is 1
When numVals is even
When numVals is even
When the elements of nums are in nonincreasing order
When the elements of nums are in nonincreasing order
When the elements of nums are in nondecreasing order
When the elements of nums are in nondecreasing order
Method maxHelper never works as intended.

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!