lab_dict - CPSC221 2019W2_ Data Structures - lab_dict CPSC221 2019W2 Data Structures lab_dict Devious Dictionaries Cleverness Through Association

lab_dict - CPSC221 2019W2_ Data Structures - lab_dict...

This preview shows page 1 - 3 out of 8 pages.

5/5/2020 lab_dict - CPSC221 2019W2: Data Structures 1/8 lab_dict Devious Dictionaries: Cleverness Through Association Due: Sunday, March 15 at 11:59 PM Assignment Description This lab is all about making you think with dictionaries. Dictionaries (aka maps or associative arrays ) are an abstract data type which stores pairs of data and can support operations like insert , find , and remove . We generally call these (key, value) pairs. The idea is to associate a key with a certain value . Hence, dictionaries are useful for when you want to quickly “lookup” a value associated with a certain key. The name dictionary comes from the more familiar physical dictionary, where you lookup the definitions of words. If we were to model a physical dictionary with an ADT dictionary the keys would be the words, and the values would be their definitions. Since dictionaries are abstract in nature, they have no prescription for what underlying structure should be used to implement them. Common choices are tree-based structures (e.g. balanced binary search trees, BTrees, &c.) or some sort of hash table. Different underlying implementations have different performance considerations, and which you use in the real world will depend on things like desired performance and what is readily available. For this lab, we’re not going to concern ourselves with the underlying implementation of dictionaries. Instead, we’ll be using dictionary types that have already been defined for us. In C++ there are two “built-in” dictionary types: std::map and std::unordered_map . Both exist in the wonderful land of the Standard Template Library (STL). The STL is a subset of the C++ Standard Library (the library a compiler must implement to be standard-compliant) which provides data containers. As the name implies, these containers are templated and thus can contain any type (which meets the restriction of the container). You’ve probably experienced at least one of the STL types so far: std::vector , which is pretty much just a super fancy array. In general, the STL types are very convenient as they provide a lot of functionality (e.g. sorting, automatic resizing) that you don’t have to bother implementing yourself. Dictionaries are amongst some of the most important abstract data types that are used in the real world. Therefore, this lab is perhaps one of the most useful labs from a real world perspective. Mastering the concepts that you see in this lab will be a tremendous help for most technical interviews and programming problems in the future.
5/5/2020 lab_dict - CPSC221 2019W2: Data Structures 2/8 C++11 Goodness auto — easy types Most of the code we present in this class uses old (C++03) style, but in this lab we encourage you to use some C++11 features to make your life easier.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture