Which STL container provides constant time access to elements but may take linear time to insert a new element? 

  • std::vector 
  • std::queue 
  • std::array 
  • std::list
The std::vector container provides constant time (O(1)) access to elements using random access iterators. However, insertions (especially in the middle or at the beginning) might take linear time (O(n)) as elements need to be shifted to make space for the new element.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *