Question 10
Back to Exercise
What is the time complexity of push_back on a std::vector?
- A Always O(1)
- B Amortized O(1) – occasionally O(n) when it reallocates Correct
- C O(log n)
- D O(n)
Correct Answer: Option B
Capacity grows geometrically, so expensive reallocations are rare enough that the average cost per push_back is constant.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!