LearnFrenzy
Sign in Take a free test

Arrays and Vectors · Arrays and Vectors MCQ · Question 10

Time complexity of vector::push_back Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links