Test Series - cpp

Test Number 72/102

Q: What is the use of front() function in heap?
A. Returns the element closest to the median of a sequence
B. Returns the last element of the heap
C. Returns the first element of the heap
D. Returns the element closest to mean of a sequence
Solution: C++ STL-heap container provides the front() function that returns the first element of the heap i.e. the maximum number of the sequence.
Q: Which function is used to insert an element into heap?
A. push_back()
B. push_heap()
C. pop_back()
D. pop_heap()
Solution: C++ STL-heap container provides push_heap() function that inserts a new element to the constructed heap.
Q: Elements in STL heap are removed in ________________________
A. decreasing order
B. increasing order
C. alternate i.e. once max element then min element
D. input order
Solution: C++ STL-heap simulates the max heap i.e. the maximum element is at the top/front of the heap hence on poping we pop the first element which is always the maximum number in the sequence.
Q: Which header file is required to use heap in your program?
A. 
B. 
C. 
D. 
Solution:  header file is required to use the functionality of the heap container provided by C++.
Q: Which of the following is correct syntax of making heap from a vector v?
A. make_heap(v.elements);
B. make_heap(v);
C. make_heap(v.end(), v.begin());
D. make_heap(v.begin(), v.end());
Solution: To construct heap usng the vector elements one need to use the following syntax make_heap(v.begin(), v.end()); which is taking the iterator to first and last element of the vector using which elements of vector can be accessed and heap can be constructed.
Q: What is the use of sort_heap() function in heap?
A. To sort the elements in the heap into descending order
B. To sort the elements in the heap into ascending order
C. To sort the first half of the heap
D. To sort the second half of the heap
Solution: C++ STL-heap container provides sort_heap() function to sort the heap into ascending order which will no longer remain a heap.
Q: Which function is used to check whether a given sequence is heap or not?
A. sort_heap()
B. is_heap()
C. is_heap_until()
D. check_heap()
Solution: C++ STL-heap container provides is_heap() function to check whether a given sequence of elements represents a heap or not. Descending order of elements represents a valid heap.
Q: What is the use of is_heap_until() function?
A. Returns the iterator of the last element of the sequence always
B. Returns the iterator to the position from where the sequence is a heap
C. Returns the iterator of the position till that the sequence is a heap
D. Returns the iterator of the first element of the sequence
Solution: C++ STL-heap container provides is_heap_until() function which returns the iterator to the position till the container is a heap. For example, we have 7 5 3 1 10 12 so till 1 the sequence forms a heap so this function will return the iterator to the position of element 1.
Q: What is vtable in C++?
A. Lookup table to resolve function calls in dynamic manners
B. Lookup table to resolve function calls in static manners
C. Lookup table to see which are the functions available for calls throughout the program
D. Lookup table to check how many functions are there int he program
Solution: vtable is a lookup table that is used to resolve the function calls in dynamic/late binding manners.
Q: Which classes can have vtable?
A. Classes having friend functions
B. Classes having virtual functions
C. Classes having static functions
D. All classes have a vtable
Solution: Classes having virtual functions only need vtable because in those cases only we need to resolve function calls in a dynamic manner.

You Have Score    /10