int sum = 0;
void calcSum(vector v, int i)
{
if(i == v.size())
return;
sum += v[i];
calcSum(v, i+1);
}
This was the question asked in C++ STL Quiz 2 Competitive Programming Course. According to me, the time complexity for the given code will be O(N) where N is vector size and initial call is calcSum(v,0). I don’t know where I am wrong. The in-built answer is O(N^2). If this is because they are saying that a copy of vector is maintained every time calcSum is called, then it arguable. But I don’t think it should be O(N^2). Complexity questions doesn’t consider these extra times. Can anyone tell me where I am wrong?