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 will be the time compleity. I think it is O(N) but the correct answer in O(N^2). How?

@vikrantwaje96 It is 0(n^2) because 0 (n) time is required in each iteration for copying the vector values onto another vector. And there is 0(n) number is steps. So it’s 0(n^2)

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.