Middle
What is the complexity of the push_back operation in std::vector?
sobes.tech AI
Answer from AI
On average, amortized O(1).
In the worst case, O(N), where N is the current size of the vector. This occurs during memory reallocation when the current capacity of the vector is insufficient for a new element. A new buffer with larger capacity is created, elements are copied there, and the old buffer is released.