Outline of Class 16: Experimenting with Vectors and Dictionaries
Held: Friday, February 13, 1998
- Assignment three is now
ready and is due next Friday.
- Assignment four is also
ready and is due the following Tuesday.
- We'll spend most of today's class on
- For Monday, read section 9.1 of Bailey.
- In our investigation of vectors, we've seen a structure that collects
objects in which the objects can be indexed by numbers.
- Are there other ways to index collections? Yes, we could index
collections by "any object".
- Collections of objects indexed by objects (e.g., strings) are called
- 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).
- Counting things (associate a counter with each object; when you
see another copy, increment the counter).
- How do we do build dictionaries? Right now, we'll just use dictionaries
and won't worry about how they work. Later, we'll look at how to build
- Some terminology:
- The objects we're using as indices are called keys.
- The objects we're looking up are called values.
- 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 all the keys in the dictionary.
- List all the values in the dictionary.
- Hash tables are one mechanism for implementing dictionaries. They
provide an implementation in which it is likely, but not guaranteed,
that access to particular elements will be quick.
- In Java,
java.util.Hashtable implements the interface
- Well ...
Dictionary isn't really an interface; it's
an abstract class. Nonetheless, it's similar enough for
- For now, you can think of hash tables as equivalent to dictionaries.
When you need a dictionary, create a hash table.