CPP Standard Template Library Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Thames
T
Thames
Community Contributor
Quizzes Created: 11982 | Total Attempts: 187,298
| Attempts: 19 | Questions: 20 | Updated: Aug 15, 2026
Please wait...
Question 1 / 21
🏆 Rank #-- ▾
0 %
0/100
Score 0/100

1. What is the primary purpose of iterators in the STL?

Explanation

Iterators provide a consistent way to traverse and access elements across different STL containers. They separate algorithms from the specific container implementation, allowing the same algorithms to work with many container types.

Submit
Please wait...
About This Quiz
CPP Standard Template Library Quiz - Quiz

This quiz evaluates your understanding of the C++ Standard Template Library (STL), a core component of modern C++ programming. You'll be tested on containers, iterators, algorithms, and functional programming concepts essential for college-level C++ development. Master STL to write efficient, reusable code.

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. What is the time complexity of std::map::find()?

Explanation

`std::map::find()` searches an ordered associative container. Because a `std::map` is typically implemented as a balanced search tree, each comparison narrows the search efficiently. The lookup therefore takes logarithmic time in the number of elements: **O(log n)**.

Submit

3. Bidirectional iterators support ______ and --.

Explanation

Bidirectional iterators can move forward and backward through a sequence: `++` advances to the next element, while `--` moves to the previous one.

Submit

4. Which container adapter is LIFO?

Explanation

`std::stack` is a LIFO (last-in, first-out) container adapter: elements are added to and removed from the same end, so the most recently added element is removed first.

Submit

5. What does std::distance() return between two iterators?

Explanation

`std::distance(first, last)` counts how many iterator increments are needed to go from `first` to `last`, returning that count as the iterator’s difference type. It measures positions in the sequence, not memory bytes; its complexity is constant for random-access iterators and linear for other iterator categories.

Submit

6. Which algorithm partitions a range based on a predicate?

Explanation

`std::partition` rearranges a range so elements satisfying a predicate come before those that do not. `std::stable_partition` performs the same separation while preserving the relative order of elements within each group. `std::sort` orders elements according to a comparison function rather than partitioning them by a predicate.

Submit

7. Which STL container provides O(1) average-case insertion and deletion?

Explanation

`std::unordered_map` uses a hash table, so inserting or deleting an element by key takes O(1) time on average. Hash collisions can make operations slower, with a worst-case time of O(n). The other options do not generally provide average-case O(1) insertion and deletion by key.

Submit

8. What does std::adjacent_find() locate?

Explanation

`std::adjacent_find()` searches a range for the first pair of neighboring elements that satisfy a comparison condition. By default, it finds two consecutive elements that are equal, and returns an iterator to the first element of that pair.

Submit

9. Which algorithm sorts a range in-place with O(n log n) complexity?

Explanation

`std::sort` orders the entire range in place and performs O(n log n) comparisons. Unlike `std::stable_sort`, it does not preserve the relative order of equivalent elements; `std::partial_sort` and `std::nth_element` arrange only part of the range.

Submit

10. Which algorithm returns an iterator to the first element satisfying a predicate?

Explanation

`std::find_if` examines elements in a range and returns an iterator to the first element for which the supplied predicate evaluates to `true`. If no element satisfies the predicate, it returns the range’s end iterator. `std::count_if` counts matches, while `std::any_of` returns a Boolean.

Submit

11. Std::priority_queue is typically implemented using a ____.

Explanation

A `std::priority_queue` is typically built on a heap, which keeps the highest-priority element at the top. This structure allows efficient access to that element and efficient insertion and removal while maintaining the priority order.

Submit

12. Std::forward_list provides ____-directional iteration.

Explanation

`std::forward_list` is a singly linked list, so each element links to the next element only. Its iterators can move forward through the list but cannot move backward, making its iteration single-directional.

Submit

13. What does std::accumulate() compute on a range?

Explanation

`std::accumulate()` processes the elements in a range using an initial value. By default, it adds each element to the running total; if given a custom binary operation, it can perform another reduction, such as multiplication or a user-defined combination.

Submit

14. Which STL container maintains insertion order and allows duplicates?

Explanation

`std::multimap` permits duplicate keys and orders elements by key, not insertion order. If the question means preserving insertion order while allowing duplicates, `std::queue` is the fitting option because it processes elements in FIFO order.

Submit

15. Which STL container guarantees contiguous memory?

Explanation

`std::vector` stores its elements contiguously in memory, allowing efficient indexed access and compatibility with APIs that require a contiguous array. In contrast, `std::list` and `std::set` use separate nodes, while `std::deque` may store elements in multiple memory blocks.

Submit

16. What is the primary advantage of std::unordered_set over std::set?

Explanation

`std::unordered_set` uses a hash table, so lookup takes constant time on average, O(1), compared with the O(log n) lookup of `std::set`, which is typically implemented as a balanced tree. This can make searches faster, though performance may degrade with many hash collisions. Unlike `std::set`, it does not maintain elements in sorted order.

Submit

17. Std::bind() creates a ______ by binding arguments to a callable.

Explanation

std::bind() takes a callable and binds specified arguments to it, producing a function object. This object can be stored and invoked later, with any unbound arguments supplied at the time of the call.

Submit

18. Std::vector is a ____-based container.

Explanation

`std::vector` is a dynamic array because it stores elements contiguously and can grow or shrink as elements are added or removed. It also provides fast indexed access, while automatically managing the memory needed for its changing size.

Submit

19. Std::function is a template wrapper for ______ types.

Explanation

`std::function` is a type-erasing wrapper that can store and invoke callable objects, such as functions, lambdas, and function objects, provided they have a compatible signature.

Submit

20. Std::copy() requires the destination iterator to be at least a ____-access iterator.

Explanation

`std::copy()` writes each source element to the destination and advances the destination iterator. Therefore, the destination needs only to satisfy the requirements of an output iterator.

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the primary purpose of iterators in the STL?
What is the time complexity of std::map::find()?
Bidirectional iterators support ______ and --.
Which container adapter is LIFO?
What does std::distance() return between two iterators?
Which algorithm partitions a range based on a predicate?
Which STL container provides O(1) average-case insertion and deletion?
What does std::adjacent_find() locate?
Which algorithm sorts a range in-place with O(n log n) complexity?
Which algorithm returns an iterator to the first element satisfying a...
Std::priority_queue is typically implemented using a ____.
Std::forward_list provides ____-directional iteration.
What does std::accumulate() compute on a range?
Which STL container maintains insertion order and allows duplicates?
Which STL container guarantees contiguous memory?
What is the primary advantage of std::unordered_set over std::set?
Std::bind() creates a ______ by binding arguments to a callable.
Std::vector is a ____-based container.
Std::function is a template wrapper for ______ types.
Std::copy() requires the destination iterator to be at least a...
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!