2.7 MapsSearching for data items based on unique key values is a very common application in computer science. An abstract data type that provides this type of search capability is often referred to as a map or dictionary since it maps a key to a corresponding value. Consider the problem of a university registrar having to manage and process large volumes of data related to students. To keep track of the information or records of data, the registrar assigns a unique student identification number to each individual student as illustrated in Figure 2.7.1. Later, when the registrar needs to search for a student's information, the identification number is used. Using this keyed approach allows access to a specific student record. If the names were used to identify the records instead, then what happens when multiple students have the same name? Or, what happens if the name was entered incorrectly when the record was initially created? In this section, we define our own Map ADT and then provide an implementation using a list. In later chapters, we will implement and evaluate the map using a variety of data structures. We use the term map to distinguish our ADT from the dictionary provided by Python. The Python dictionary is implemented using a hash table, which requires the key objects to contain the As you learned in Chapter 2, there may be multiple data structures and ways to organize the data that are suitable for implementing an abstract data type. Thus, it's not uncommon for language libraries to provide multiple implementations of an abstract data type, which allows the programmer to choose the best option for a given problem. Your ability to choose from among these various implementations will depend not only on your knowledge of the abstract data type itself, but also on understanding the pros and cons of the various implementations. We will explore the implementation details of Python's dictionary later in Chapter 11 when we discuss hash tables and the design of hash functions.
The Map ADTThe Map ADT provides a great example of an ADT that can be implemented using one of many different data structures. Our definition of the Map ADT, which is provided next, includes the minimum set of operations necessary for using and managing a map. The Map ADT
In the next section, we explore the use of the map operations with a basic example. Following which, we turn our attention to the physical implementation of the Map ADT.
|