Time Complexity

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);
}
what is the time complexity of the above code

@dare_devil_007 Hey try to see how the function stack would change and work for some small value of n, say n=5.
Also this code is having recurrence relation
T(n)=T(n-1)+k
Which will give use the time complexity of O(n)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

but the answer for this is given as O(N^2) in the quizz

@dare_devil_007 Hey there must be some mistake this is an O(n) code, I will notify them.