Predict the time complexity of the following recursive function, given the vector is of size N and the initial call is calSum(v, 0).
int sum = 0;
void calcSum(vector v, int i)
{
if(i == v.size())
return;
sum += v[i];
calcSum(v, i+1);
}
O(N)
O(N^2)
Depends upon the compiler, but O(N) in most cases.
Depends upon the compiler, but O(N^2) in most cases.
Answer must be O(n) right?