Question: Find the max value of an array using recursion. Section 2.4.2 in Chapter 2 of your textbook discusses a way to recursively process an array.

Find the max value of an array using recursion.

Section 2.4.2 in Chapter 2 of your textbook discusses a way to recursively process an array. Binary search is used as an example and C++ code for the binary search is given on page 70. Each call to the recursive binary search function processes a portion of the array identified by the first and last indexes of the subarray of the subarray to be processes by this call.

Section 2.4.3 in Chapter 2 discusses how to find the largest element in an array using the same recursive technique that was covered in the previous section. Pseudocode for a function called maxArray is given on page 72 of your textbook.

Your job is to write an implementation for a C++ function called maxArray that will return the largest value in an integer array. You must also write a driver (program to test your function). You can put your maxArray function and your driver program in the same file if you want.

Here is a version of the algorithm from the textbook that is worded slightly differently. Note that the array to be processed is called anArray.

 if (anArray has only one entry) return the value of that entry else if (anArray has more than one entry) return the maximum of maxArray(left half of anArray) and maxArray(right half of anArray) 

Please include both the maxArray function and the driver program.

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!