This set of C++ Programming Multiple Choice Questions & Answers (MCQs) focuses 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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.
6. Unordered map is implemented using _________________
a) binary search tree
b) red black tree
c) heap
d) hash table
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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.
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
View Answer
Explanation: 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.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Computer Science Books
- Apply for C++ Internship
- Practice Programming MCQs
- Practice Computer Science MCQs
- Apply for Computer Science Internship