LearnFrenzy
Sign in Take a free test

STL Containers · Exercise 1 of 4

STL Containers STL Containers MCQ

  • 20 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on C++ STL containers: vector, deque, list, set, map, unordered_map, adapters, complexities and iterator invalidation. Pick an option to check your answer instantly.

Question 1 Easy

Which container is recommended as the default sequence container in C++?

A std::list
B std::vector
C std::deque
D std::set
Question page & discussion
Question 2 Easy

How is std::map typically implemented?

A Hash table
B Balanced binary search tree (red-black tree)
C Sorted vector
D Linked list
Question page & discussion
Question 3 Easy

What is the average time complexity of find() in std::unordered_map?

A O(log n)
B O(1)
C O(n)
D O(n log n)
Question page & discussion
Question 4 Easy

What happens when you insert a value that is already in a std::set?

A A second copy is stored
B Nothing – set keeps unique keys; insert reports false
C An exception is thrown
D The old value is replaced
Question page & discussion
Question 5 Easy

Which operation is O(1) for std::deque but O(n) for std::vector?

A Access by index
B Insertion at the front
C Insertion at the back
D size()
Question page & discussion
Question 6 Easy

Why does std::list not provide operator[]?

A It is deprecated
B Reaching the i-th node needs O(i) pointer hops, so random access is not offered
C Lists are read-only
D It uses at() instead
Question page & discussion
Question 7 Medium

m is a std::map<std::string, int> without the key "x". What does int v = m["x"]; do?

A Throws std::out_of_range
B Inserts "x" with value 0 and returns 0
C Returns garbage
D Does not compile
Question page & discussion
Question 8 Easy

With the default comparator, what does std::priority_queue<int>::top() return?

A The smallest element
B The largest element
C The first inserted element
D The last inserted element
Question page & discussion
Question 9 Medium

Which container does std::stack use underneath by default?

A std::vector
B std::deque
C std::list
D std::array
Question page & discussion
Question 10 Medium

Which operation can invalidate all iterators to a vector's elements?

A Reading v[0]
B A push_back that causes reallocation
C Calling size()
D Sorting a copy
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links