← Quiz: STL Containers: all 9 questions
Quiz: STL Containers · Question 9 of 9
Inserting at the front of a large vector with v.insert(v.begin(), x) is slow. Why?
Inserting at the front of a large vector with v.insert(v.begin(), x) is slow. Why?
- A.vector must sort itself after every insert
- B.Every existing element has to shift one place to the right
- C.vector allocates a new block for each insert
- D.Inserting at the front is not allowed
Answer & explanation
Correct answer: Every existing element has to shift one place to the right
Shifting n elements costs O(n); deque or list handle front insertion better.
Can you get the rest right without peeking?
Take the timed Quiz: STL Containers quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →