Lecture 24
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.
- Identify applications where hash tables can be useful.
- Use STL hash table based sets and maps.
Reading assignment
- Sections 5.1, 5.2, and 5.6.
- Lecture: Hash functions.
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. (Post your answer on the discussion board)
- Give an example of two words in English where the hash function of slide 9 will have the same hash values. Give a similar example for the hash function of slide 11. Which example was easier to find? (Post your answer on the discussion board)
/usr/lib/spell/hashmake
onprogram
gives hash values for strings. Which hash function do you consider better, the hash function of slide 11 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.- What difficulties would we face if we changed
hashmapex.cpp
and replacedstring
with C stylechar *
?- Questions on next lecture's material
- None.
Last modified: 27 Oct 2011