Test Series - cpp

Test Number 82/102

Q: Unordered map is implemented using _________________
A. binary search tree
B. red black tree
C. heap
D. hash table
Solution: As unordered map has no order of keys therefore hash table is used to store key-value pairs in a hash table.
Q: Map is implemented using ________________
A. binary search tree
B. red black tree
C. heap
D. hash table
Solution: 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.
Q: 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
Solution: 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.
Q: Which of the following queue container can expand or shrink from both directions?
A. deque
B. queue
C. priority queue
D. stack
Solution: 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.
Q: 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
Solution: 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.
Q: What is the header file used for declaring the standard library algorithms?
A. container
B. algorithm
C. library
D. iterator
Solution: C++ Standard Library, algorithms are components that perform algorithmic operations on containers and other sequences. For this operation, We have to use  header file.
Q: Pick out the correct method in the c++ standard library algorithm.
A. mismatch
B. maximum
C. minimum
D. maxmatch
Solution: It is a method in the search operation in standard library algorithms.
Q: What is the use of make_heap in the heap operation?
A. Rearrange a heap
B. Deform a heap
C. Form a heap
D. Delete a heap
Solution: It is used to rearranges a range so that it becomes a heap.
Q: What is the type of the first item in the heap?
A. Bigger than others
B. Lower than others
C. Mean value of the heap
D. Equal to others
Solution: In C++, when we say heap we mean max heap and first element of max is bigger than others.
Q: Pick out the correct library in the following choices.
A. Search
B. Generate
C. Numeric
D. All of the mentioned
Solution: These are the available libraries in C++.

You Have Score    /10