Time Complexity

How come time complexity of this snippet is O(N^2) instead of O(N) -
int sum = 0;
void calcSum(vector v, int i)
{
if(i == v.size())
return;
sum += v[i];
calcSum(v, i+1);
}

hi @debhowmicksayan_df0382a1e2ea3b66,
here the vector is being passed by value so everytime u call the function vector of size n is copied and that’s happening for n times so its o(n2)

So if we use vector &v then it will be O(N) right?

@debhowmicksayan_df0382a1e2ea3b66 yes

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.