Container Characteristics

IN what follows, we briefly describe each container, along with the main differences between the different classes within each category.


Sequence Containers

Sequence containers store elements in a linear fashion, where the order of insertion is preserved.

  1. std::array:

  2. std::vector:

  3. std::deque (Double-ended queue):

  4. std::list:

  5. std::forward_list:

Key Differences: - array: Fixed size, fast random access. - vector: Dynamic, fast random access, efficient back insertions. - deque: Fast insertions/removals at both ends. - list: Fast insertions/removals anywhere but slower access. - forward_list: Lightweight, single-direction traversal.


Associative Containers

Associative containers store elements in a specific order based on their keys, typically using binary search trees (balanced).

  1. std::set:

  2. std::map:

  3. std::multiset:

  4. std::multimap:

Key Differences: - set/multiset: Focus on element uniqueness and order. - map/multimap: Focus on key-value associations, where multimap allows duplicate keys.


Unordered Associative Containers

These containers store elements based on hash tables, offering fast average-time complexity for search, insert, and delete, but without any guaranteed order.

  1. std::unordered_set:

  2. std::unordered_map:

  3. std::unordered_multiset:

  4. std::unordered_multimap:

Key Differences: - unordered_set/unordered_multiset: Focus on element uniqueness without ordering. - unordered_map/unordered_multimap: Focus on key-value associations without ordering, and unordered_multimap allows duplicate keys.


Container Adaptors

Container adaptors provide a restricted interface over sequence containers, tailoring them for specific use-cases like stacks or queues.

  1. std::stack:

  2. std::queue:

  3. std::priority_queue:

Key Differences: - stack: LIFO behavior (last-in, first-out). - queue: FIFO behavior (first-in, first-out). - priority_queue: Retrieves elements by priority, not insertion order.


Summary of Main Differences

This overview should help clarify when and why to use each container!

Previous Page | Course Schedule | Course Content