Question: Write two recursive versions of the function minInArray . The function will be given a sequence of elements and should return the minimum value in

Write two recursive versions of the function

minInArray

. The function will be given a

sequence of elements and should

return the minimum value in that sequence.

The two versions

differ from one another in the technique we use to pass the sequence to the function.

In version 1 - The portotype function should be:

int minInArray1(int arr[],int arrSize)

Here, the function is given arr, an array of integers, and its logical size, arrSize

The function should find the minimum value out of all the elements in positions:

0, 1, 2, ..., arrSize-1.

In version 2 The prototype of the function should be:

int minInArray2(int arr[], int low, int high)

Here, the function is given arr, an array of integers and two addittional indices: low and high

(low Write two recursive versions of the function minInArray . The function will high), which indicates the range of incides that need to be considered.

The function should find the minimum value out of all the elements in positions:

low, low+1, ..., high

Use the following main to check your program:

int main() { int arr[10] = {9, -2, 14, 12, 3, 6, 2, 1, -9, 15}; int res1, res2, res3, res4;

res1 = minInArray1(arr, 10); res2 = minInArray2(arr, 0, 9); cout

res3 = minInArray2(arr, 2, 5); res4 = minInArray1(arr+2, 4); //arr+2 is equivalent to &(arr[2]) cout

return 0;

}

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!