250+ TOP MCQs on More Containers and Answers

C++ Programming Multiple Choice Questions & Answers (MCQs) on “More Containers”.

1. Which container is used to store elements as key-value pair?
a) map
b) multimap
c) unordered map
d) all of the mentioned
Answer: d
Clarification: C++ provides these three containers(map, multimap and unordered map) to store elements as key-value pair.

2. Which container can have the same keys?
a) map
b) multimap
c) unordered map
d) set
Answer: b
Clarification: C++ provide multimap container that is used to make map that can contain same keys i.e. {a: 5} and {a:10} both can exist.

3. Which container is best to keep the collection of distinct elements?
a) multimap
b) heap
c) set
d) queue
Answer: c
Clarification: C++ provides a set container to store a collection of distinct elements. This container behaves similar to mathematical sets.

4. Which container is used to keep priority based elements?
a) queue
b) stack
c) set
d) priority queue
Answer: d
Clarification: C++ provides priority queue container that stores elements based on their priority. For example, if the absolute value is the priority then -6 will be kept before 4 in the priority queue.

5. Sets are implemented using _______________________
a) binary search tree
b) red black tree
c) avl tree
d) heap
Answer: a
Clarification: Sets are implemented using the search tree so that we can check the presence of any element to be inserted in O(logn) time in order to remove conflicts between elements.

  250+ TOP MCQs on Exceptions and Efficiency and Answers

6. Unordered map is implemented using _________________
a) binary search tree
b) red black tree
c) heap
d) hash table
Answer: d
Clarification: As unordered map has no order of keys therefore hash table is used to store key-value pairs in a hash table.

7. Map is implemented using ____________________
a) binary search tree
b) red black tree
c) heap
d) hash table
Answer: b
Clarification: The map has some order of stored keys therefore red black tree is used to maintain that order and access the elements as soon as possible.

8. Which of the following is correct about the map and unordered map?
a) Ordering of keys in maps whereas no such order in the unordered map
b) Maps are implemented red-black trees whereas unordered map are implemented using hash tables
c) Average search time in the unordered map is O(1) whereas it is O(logn) in case of maps
d) All of the mentioned
Answer: d
Clarification: All the above mentioned points are correct about maps and unordered maps. Maps uses red-black tree whereas unordered map uses hash tables therefore the average search time for the unordered map is O(1) whereas it is O(logn) in case of maps.

9. Which of the following queue container can expand or shrink from both directions?
a) deque
b) queue
c) priority queue
d) stack
Answer: a
Clarification: Deque is a short form for a doubly ended queue which can be expanded and shrinked from any side of the queue either from the front or from the back.

  250+ TOP MCQs on Sizes and Answers

10. Which of the following is correct about map and multimap?
a) Map can have same keys whereas multimap cannot
b) Implementation of maps and multimap are different
c) Multimap can have same keys whereas the map cannot
d) Average search time of map is greater than multimap
Answer: c
Clarification: Multimap is similar to map, the only difference that they have is that in multimap elements can have the same keys where in the map we have only one to one key-value pair correspondence.

Global Education & Learning Series – C++ Programming Language.

Leave a Comment

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

Scroll to Top