Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a recursive function that finds and returns the minimum element in an arra

ID: 3573595 • Letter: W

Question

Write a recursive function that finds and returns the minimum element in an array, where the array and its size are given as parameters Function prototype: Int findmin(int a[], int n); // return min element in a[] C++ Write a recursive function that finds and returns the minimum element in an array, where the array and its size are given as parameters Function prototype: Int findmin(int a[], int n); // return min element in a[] C++ Function prototype: Int findmin(int a[], int n); // return min element in a[] C++

Explanation / Answer

Please find the below code for finding minimum element through recursion:

i

int minbyrecursion(int a[],int n)

{

                int minval;

                if(n==1)

                return a[0];

//this case is basically to counter if the array has only one element in it else it goes inot the recursion mode of finding the element

                else

                {

                                min= minbyrecursion (a,n-1);

                                                //send the array one size less everytime so as to reach the last element of the array

//As we know that recursion follows a top down or bottom up approach here we are following a top down approach

                                if(min<a[n-1])

                                {

                                return min;

                                }

                                else

                                return a[n-1];

                }

}

thanks a lot for teh question . do let me know if you have queries

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote