Q3 why is not O(n) but O(n^2)

Q3 why is not O(n) but O(n^2)

hello @vishwajeetss861999
how vector is passed in function is it pass by value or pass by reference.

if it is passed by value (ie vector < int > v ) then time complexity will be O(n^2)
reason-> total n calls will be there and in each call old vector get copied to new vector which will take O(n) operation so in total n * n operation which is equivalent to O(n^2).

if it passed by reference(i.e vector < int > &v ) then simply O(n) because n calls and for each call O(1) operation so total n*1 operation which is equivalent to O(n)