How is the complexity of inbuilt-swap function is O(1), will it change the names of the vector only? otherwise for the swapping of the elements, will not the maximum possible time will be O(N+M). Please explain this concept.
Vector Quiz STL 4
Hey @Sakshi2004
vector are dynamically created arrays so we just swap the address of inbuilt pointer which is O(1)
Similar to this
int*a=10;
int*b=20;
int*c=a;
a=b;
b=c;
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.