Basics

  • N: number of elements
  • m: size of hash table

Collision Handling

Separate Chaining

  • Linked list

Open Addressing

  1. To inert a key , compute
  2. If is empty, insert it here
  3. If collision occurs, probe alternative cell in the following order: , until an empty cell is found
  4. , where the function determines the collision resolution strategy and
  5. Different open addressing methods differ in the definition in the function

Linear probing

  • Can always insert unless the table is full
  • Worst case for insertion is O(n)
  • Insertion can merge 2 cluster, making subsequent insertion slower
  • Each insertion must increase size of cluster by 1

Quadratic probing

  • Different home positions will have different probe sequences
  • If the table size is prime, then a new key can always be inserted if the table is at least half empty
  • To avoid secondary clustering, the probe sequence need to be a function of the original key value, not the home position (double hashing)

Double hashing

e.g. , where and is prime

  • hash2 cannot be zero
  • For any key , must be relatively prime to the table size , otherwise we will only be able to examine a fraction of the table entries

Lazy Deletion

  • load factor