C++ Programming Questions and Answers – More Containers

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

Answer: d
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

Answer: b
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

Answer: c
Explanation: C++ provides a set container to store a collection of distinct elements. This container behaves similar to mathematical sets.
advertisement
advertisement

4. Which container is used to keep priority based elements?
a) queue
b) stack
c) set
d) priority queue
View Answer

Answer: d
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

Answer: a
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

Answer: d
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

Answer: b
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.
advertisement

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

Answer: d
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

Answer: a
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.
advertisement

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

Answer: c
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.