Q:

C++ recursively find minimum value of array

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));
    }
}

A:

It's a little silly to worry about efficiency, given that there is an obvious, non-recursive way to do it in O(n), one pass. There is even an STL algorithm std::min_element. But then, it's a silly assignment. FIrst be sure your solution is correct. When n==0, will a[0] be valid? Generally, such an n indicates the length of the array, not the lowest index.
To go from O[n^2] to O[n], be sure to compare each element only once. That implies not starting at the beginning of the array on every pass.
#include <algorithm>
#include <cassert>

int findmin(const int a[], int n)
{
    assert(n>0);
    if(n == 1)  // See heyah.
        return a[0];
    else
    {
        return std::min(a[0], findmin(a + 1, n - 1));
    }
}

In for-real C++ code, if for some reason we were saddled with the old fashion function signature, we would do something like this:
int findmin(const int a[], int n) {
    if(n<=0) { throw std::length_error("findmin called on empty array");}
    return *std::min_element(a, a+n);
}

A:

You could do conditional operator ?: to get rid of bunch if else statements, to make function cleaner. And instead of calling findmin() twice you could assign return value to variable inside of the statement, this is main advantage of this code vs. original one.
int findmin(const int a[], int n) {
   if (n == 0) // base case
      return a[0];

   return a[n] < (int min = findmin(a, n - 1)) ? a[n] : min;
}

This (a[n] < (int min = findmin(a, n - 1)) ? a[n] : min;) could be done using if statement as well:
if (a[n] < (int min = findmin (a, n - 1))
     return a[n];
else
     return min;

EDIT:
Per many reputable sources, this is O(n) time. O (n^2) would be if we are comparing each element with all the other elements.

