I have an assignment for a c++ programming class to write a recursive function without the use of static variables, with the following prototype: int findmin(const int a[], int n);
My solution works (for very small arrays), however I think ~2^n complexity is excessive and could be improved.
Are there any improvements that could be made within the specified criteria that would make this more efficient?
int findmin(const int a[], int n)
{
if(n == 0)
return a[0];
else
{
if(a[n-1] < findmin(a,(n-1)))
return a[n-1];
else
return findmin(a,(n-1));
}
}