Book contents
9 - Hash Tables
Published online by Cambridge University Press: 25 January 2011
Summary
Hash tables are a dictionary structure of great practical importance and can be very efficient. The underlying idea is quite simple: we have a universe U and want to store a set of objects with keys from U. We also have s buckets and a function h from U to S = {0, …, s − 1}. Then we store the object with key u in the h(u)th bucket. If several objects that we want to store are mapped to the same bucket, we have a collision between these objects. If there are no collisions, then we can realize the buckets just as an array, each array entry having space for one object. The theory of hash tables mainly deals with the questions of what to do about the collisions and how to choose the function h in such a way that the number of collisions is small.
The idea of hash tables is quite old, apparently starting in several groups at IBM in 1953 (Knott 1972). For a long time the main reason for the popularity of hash tables was the simple implementation; the hash funcions h were chosen ad hoc as some unintelligible way to map the large universe to the small array allocated for the table. It was the practical programmer's dictionary structure of choice, easily written and conceptually understood, with no performance guarantees, and it still exists in this style in many texts aimed at that group.
- Type
- Chapter
- Information
- Advanced Data Structures , pp. 374 - 405Publisher: Cambridge University PressPrint publication year: 2008