Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6636677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:12:58+00:00 2026-05-25T23:12:58+00:00

I learned the complexity of deque::insert() from the C++ standard 2003 (chapter 23.2.1.3) as

  • 0

I learned the complexity of deque::insert() from the C++ standard 2003 (chapter 23.2.1.3) as follows:

In the worst case, inserting a single element into a deque takes time linear in the minimum of the distance from the insertion point to the beginning of the deque and the distance from the insertion point to the end of the deque.

I always understand the implementation of stl deque as a collection of memory chunks. Hence an insertion will only affect the elements in the same memory chunk as the insertion position. My question is, what does the standard mean by “linear in the minimum of the distance from the insertion point to the beginning of the deque and the distance from the insertion point to the end of the deque”?

My understanding is because C++ standard does not enforce a certain implementation of deque. The complexity is just in general for the worst case. However, in the actual implementation in compilers, it is linear to the number of elements in a memory chunk, which may vary for different element sizes.

Another guess might be that, since insert() will invalidate all iterators, deque needs to update all iterators. Therefore it’s linear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:12:58+00:00Added an answer on May 25, 2026 at 11:12 pm

    std::deque is normally (always?) implemented as a collection of chunks of memory, but it won’t normally insert a whole new chunk just for you to insert one new element in the middle of the collection. As such, it’ll find whether the insertion point is closer to the beginning or end, and shuffle the existing elements to make room for the new element in an existing chunk. It’ll only add a new chunk of memory at the beginning or end of the collection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What are the Complexity guarantees of the standard containers? From the answers
I learned today that NetBeans 6.5 should have an on-the-fly compilation of (single) Java
I learned to use "exists" instead of "in". BAD select * from table where
I learned that by trying to use the tablesorter plug in from jquery the
I learned everything I know about Rails from Railscasts. Now I want to learn
I learned from ----As to when default promotions kick in: default argument promotions are
I learned from this article that to avoid confliction between javascript libraries, use jQuery.noConflict();
i have learned that a program is measured by it's complexity - i mean
I learned enums when I learned C and from time to time I keep
I learned from android dev tutorial and now I can make ListView. and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.