What are the trade-offs of using std::deque over std::vector?

Last updated 21 June 2026

  • std::deque offers amortized O(1) push_front/push_back, and end insertions don't invalidate references to existing elements (iterators may still be invalidated).

  • It is stored as multiple chunks, not one contiguous block: worse cache locality, slower operator[], more memory overhead, and no data() for C APIs.

  • Default to std::vector. Use deque when you need fast insertion/removal at both ends, such as a queue.

  • https://www.geeksforgeeks.org/cpp/deque-vs-vector-in-c-stl/
  • https://www.vervecopilot.com/interview-questions/can-deque-c-be-the-secret-weapon-for-acing-your-next-interview
All C++ interview questions