Chapter 20 - Worked Exercises 1

Exercise 1 - Recap

Part 1

  1. Provide 3 examples of STL sequential containers.

  2. Provide 2 examples of STL associative containers.

  3. What is the difference between sequential containers and associative containers?

Part 2

State the data structure that is internally used for each of the containers below:

  1. std::vector

  2. std::list

  3. std::deque

  4. std::set

  5. std::unordered_set

  6. std::map

  7. std::unordered_map

Below are the options to chose from:

  • Linked list

  • Chunks of dynamic arrays

  • Hash sets

  • Binary search trees

  • Dynamic array

Part 3

What is the difference between std::set and std::map?

Exercise 2 - Applications

Part 1

Describe 3 applications where the use of an std::map is suitable. In each scenario, write the declaration of the container, showing clearly the type of the key and value respectively.

Part 2

Write an application that works as an English dictionary, where each word bears a single definition.

  • Which container would you choose? Write the declaration for the container.

  • Insert three entries into the container.

  • Get a word from std::cin, and look up its definition in the container, and print it back to the user.

Last updated

Was this helpful?