Vector quiz doubt

please explain question 3?

@Shreya-Gupta-2383169445069382
assumming vector is defined as vector< int > v
its time complexity will be O(n^2).
because total n calls wiil be there and on every call vector get copied to new vector which is O(n) for each call . therefore O(n^2) for n calls

Why will the vwctor be copied?

In C++ when you pass a vector to a function instead of a pointer a copy of the vector is created and passed to the function. This is how it was intended to work by the creators of the library

So that means every time a vector is passed to a function a minimum of O(n) time will be taken on each call?

Yes, since every time new vector would be created cost would be 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.