Lecture 25
Learning objectives
After this class, you should be able to:
- Describe the idea of hashing and desirable features of hash functions.
- Given a hash function, compute the hash value of an item.
- Given a hash function, the hash table size, and a sequence of insertions, draw the state of the open-addressed hash table after the insertions are complete.
- Explain how collisions are resolved in open-addressed hashing, and define linear probing.
- Given a hash function, the hash table size, a collision resolution strategy, and a sequence of insertions and searches, give the number of hash table entries searched in each insert and search operation.
- Derive the worst case and expected case time complexities for hash table insertion and search.
- Identify applications where hash tables can be useful.
Reading assignment
- Chapter 10, up to (and including) section 10.2.1, class notes.
Exercises and review questions
- Exercises and review questions on current lecture's material
- Give an application where a hash table will be better than other data structures that we have discussed.
- Give an example of two words in English where the hash function
f1
, mentioned in class, will have the same hash values. Give a similar example forf2
. Which example was easier to find?/usr/lib/spell/hashmake
onprogram
gives hash values for strings. Which hash function do you consider better,f2
or the one used byhashmake
? This is an open ended question, and the answer depends on the application. You might, for instance, evaluate the two methods by studying the distribution of hash values for words in/usr/share/lib/dict/words
or text files that you think are representative of words encountered in practice.- Show the state of an open-addressed hash table of size
23
withp(i) = i + 3
after the following sequence of operations are complete. Also give the number of hash table entries searched for each of the following operations. Use the functionf1
defined in class, for the hashing.insert("abcd"), insert("dbcd"), search("decd"), insert("abdc"), insert("bbcd"), insert("dabc"), search("decd"), insert("decd")
.- Questions on next lecture's material
- None.
Last modified: 8 Apr 2008