How we can swap two vectors? we can only swap two elements right?

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)

There is a swap funtion specifically for vectors in STL.
Swapping of the vectors will work with the complexity O(1)
Refer this for more details:

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.

Wow i get to know about today that in vector::swap address are swaped not the whole vector elements one by one
so its complexity is O(1)
Thanks bhaiya