Question: Warm-up 3 Consider a recursive function to find the maximum value in an array of integers. The function declaration is: int maxValue( int vals [],

 Warm-up 3 Consider a recursive function to find the maximum value

Warm-up 3 Consider a recursive function to find the maximum value in an array of integers. The function declaration is: int maxValue( int vals [], int size); Note, while we typically would want the "correct array size to be passed to functions like this. There's no reason that you can't call a function with a shorter "size" if you only want the beginning of the array to be considered. (Hint: you will need to use this trick and "change the size of the array in recursive calls) 1. Begin by describing the base case(s): When is it easy to find the maximum value in an array? 2. Describe the recursive case. (Hint: describe the original problem using the base case, or similar logic, in combination with some reduced form of the problem. Some of you will find this easier to treat as two bases cases, others may find this easier to think of as one base case. 3. For each base case, describe why this base case is correct (I.E. will always return the correct value if given an array that triggers the base case) 4. For each recursive case, describe why this recursive case is correct (I.E. consider the first time the function is called from main() - assume that the recursive call returns correctly and describe how you know the primary function call will, therefore, also return the correct value) 5. For each recursive case, describe how you know that it is moving closer to the base case 6. Write the complete function definition for maxValue

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!