Separate chaining is a method for dealing with hash collisions by representing a hash table as an array of linked lists or buckets. The th list in the array contains all the items that hash to the value of .
Thus, operations like search, insertion, and deletion reduce to the corresponding problem in linked lists. If there are keys and they are distributed uniformly in a table, each list will contain roughly elements, making them a constant size when .
Chaining is intuitive but devotes a lot of memory to pointers. This is space that could be used to make the table larger, which reduces the likelihood of collisions. This is why Open Addressing tends to be the preferred method for high-performance hash tables.
Given that
- Chaining costs to initialize an -element hash table with null elements prior to the first insertion.
- Traversing all the elements in the table takes ) time, where is the actual number of insertions. This is because we have to visit each of the buckets and all elements within those buckets. The accounts for visiting each bucket, even those that are empty.