Held: Tuesday, 29 April 2003
Today we consider another central ADT, the Dictionary.
Dictionaries are, in effect, arrays indexed by arbitrary values.
- Exam 3 is now graded.
We'll spend a few minutes discussing it.
- Are there questions on exam 4?
- Introduction to the Dictionary ADT
- More Details.
- Dictionaries vs. Databases.
- In our investigation of vectors and arrays, we've seen structures that
collect objects in which the objects can be indexed by numbers.
- Are there other ways to index collections? Yes, we could index
collections by strings.
- We could also index by other objects (Strings, Integers, whatever).
- Collections of objects indexed by objects are called dictionaries.
- Some people also refer to them as keyed tables.
- Some more terminology:
- The objects we're using as indices are called keys.
- The objects we're looking up are called values.
- Why do we do we want dictionaries? They make many tasks more
- Keeping track of objects we've seen. If an object is an index in
the dictionary, we've seen it; if it's not an index in the dictionary,
we haven't seen it. This would be helpful for our puzzle solver.
- Counting things We can use the dictionary to associate a
counter with each object; when you see another copy, increment the
- Databases. There are a number of techniques for implementing and thinking
about databases. Dictionaries provide a simple mechanism for
- How do we do implement dictionaries? There are a number of techniques,
including linked lists of key/value pairs.
and won't worry about how they work. Later, we'll look at how to build
- What features do we need in a dictionary? Some are similar to those
we need for vectors.
- Add something to the dictionary (requires a key and value).
- Look up something in the dictionary (requires a key, returns a value).
- Remove something from the dictionary.
- Others correspond more to the different structure of dictionaries.
- List/iterate all the keys in the dictionary.
- List/iterate all the values in the dictionary.
- Note that dictionaries are not the same as databases.
- Why not? There are a number of reasons.
- Dictionaries have a single key, and that key provides the only
way to access information.
- Databases may have multiple keys. You may also access information
using other fields. For example, while a database may be keyed by
ID#, you might still be able to search by name.
- A dictionary returns a single object given a request.
- A database may return multiple objects (e.g., all the students with
- Use a simple
KeyedValue structure (that stores a
key and a value).
- Shove 'em in a list.
- Search through the list step by step.
- We may develop code in class.
Thursday, 15 January 2003 [Samuel A. Rebelsky]
- Created as a mostly-blank outline.