plz explain this i am not getting
Time complexity
Paste the question here in which you want to know about time complexity.
Given two vectors v1 and v2, we can swap the contents of the two vectors manually using a O(N + M) time algorithm where N = v1.size() and M = v2.size().
However the vector class provides an inbuilt function swap().
What is the time complexity of v1.swap(v2) ?
O(N)
O(1)
O(M)
O(N + M)
Answer for this should be O(1) as, Here it is written that it takes constant time. It might be just changing names of the vector.
lets say
v1 = {1,2,3,4};
v2 = {1,2};
after swapping =>
v2 = {1,2,3,4}
v1 = {1,2}
so v1 and v2 now points to different vector, without accessing the elements of the vector.
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.