Q: C++ "[ ]" operator I recently read this question, and on searching a bit I found that for vectors(any many more containers) [ ] operator in c++
actually returns reference and thus O(1) complexity , just above it, it is mentioned that = operator has linear time complexity, so my question is if I have a multidimensional vector v and I do something like :
v[i]=v[j];

will it be constant time operation or linear time and why? somewhere I have read it's O(1) but I am not sure.
This was the blog in which an algorithm was being discussed, and in this comment's second line the user said it's O(1)(here v is an multidimensional vector/ array of vector), and it's the key thing in this algorithm, if it's not, I think the algorithm won't be of same complexity,
Thanks!

A: The copying of an entire std::vector<T> is O(N) as each element T needs to be copied.
All overloads of std::vector<T>::operator[] are required by the C++ standard to have constant complexity. Normally it's implemented using pointer arithmetic on the data in the std::vector.
So, v[i] = v[j]; is O(1).
The fact that T could be arbitrarily multidimensional does not matter here. A vector copy is O(N) since if you double the number of elements, you double the time (in some limit anyway). The vector element copy is O(1) since it does not depend on the number of elements in the vector.
