Linear Probing

  • Check spots in this order:
    • hash(k), hash(k)+1, hash(k)+2, etc.
     
  • hash(k) = 3k+7
    • Which is then mod'ed by the table size (10)
    • Result: hash(k) = (3k+7) mod 10
     
  • Insert: 4, 27, 37, 14, 21
    • hash(k) values: 19, 88, 118, 49, 70, respectively

Quadratic Probing

  • Check spots in this order:
    • hash(k)
    • hash(k)+12 = hash(k)+1
    • hash(k)+22 = hash(k)+4
     
  • hash(k) = 3k+7
    • Insert: 4, 27, 14, 37, 22, 34
      • hash(k) values: 19, 88, 49, 118, 73, 109, respectively

Double Hashing

  • Check spots in this order:
    • hash(k)
    • hash(k) + 1 * hash2(k)
    • hash(k) + 2 * hash2(k)
     
  • hash(k) = k
    • Result: hash(k) = k mod 10
  • hash2(k) = 7 - (k mod 7)
     
  • Insert: 89, 18, 58, 49, 69, 60

Double Hashing Thrashing

  • hash(k) = k mod 10 
    • Same as the previous slide
    • Result: hash(k) = k mod 10
     
  • hash2(k) = (k mod 5) +1
     
  • Insert: 10, 12, 14, 16, 18, 36