next up previous
Next: Analysis of Open Addressing Up: l5 Previous: Double Hashing

Example

Given input (9371, 3723, 9873, 9769, 8679, 1239, 4584), and a hash function h(x) = x mod 10, show the resulting open-addressed hash table using

  1. linear probing

      +----+
    0 |8679|  h(9371, 0) = 1
      +----+
    1 |9371|  h(3723, 0) = 3
      +----+
    2 |1239|  h(9873, 0) = 3 COLLISION!  h(9873, 1) = 4
      +----+
    3 |3723|  h(9769, 0) = 9
      +----+
    4 |9873|  h(8679, 0) = 9 COLLISION!  h(8679, 1) = 0
      +----+
    5 |4584|  h(1239, 0) = 9 COLLISION!  h(1239, 1) = 0 COLLISION!
      +----+     h(1239, 2) = 1 COLLISION!  h(1239, 3) = 2
    6 |    |
      +----+  h(4584, 0) = 4
    7 |    |
      +----+
    8 |    |
      +----+
    9 |9769|
      +----+
    

  2. double hashing with hash function h2(x) = (x mod 5)

    Note that 10 is a multiple of 5, so this is not an effective choice for a secondary hash function.

              h(9371, 0) = 1 + 0 = 1
      +----+
    0 |    |  h(3723, 0) = 3 + 0 = 3
      +----+
    1 |9371|  h(9873, 0) = 3 + 0 = 3 COLLISION!
      +----+     h(9873, 1) = ((3 + 1*(9873 mod 5)) mod 10) = 3 + 3 = 6
    2 |    |
      +----+  h(9769, 0) = 9 + 0 = 9
    3 |3723|
      +----+  h(8679, 0) = 9 + 0 = 9 COLLISION!
    4 |4584|     h(8679, 1) = ((9 + 1*(8679 mod 5)) mod 10) = (9 + 4) mod 10 = 3
      +----+     COLLISION!
    5 |1239|     h(8679, 2) = ((9 + 2*(8679 mod 5)) mod 10) = (9 + 8) mod 10 = 7
      +----+
    6 |9873|  h(1239, 0) = 9 + 0 = 9 COLLISION!
      +----+     h(1239, 1) = ((9 + 1*(1239 mod 5)) mod 10) = (9 + 4) mod 10 = 3
    7 |8679|     COLLISION!
      +----+     h(1239, 2) = ((9 + 2*4) mod 10) = (9 + 8) mod 10 = 7 COLLISION!
    8 |    |     h(1239, 3) = ((9 + 3*4) mod 10) = (9 + 12) mod 10 = 1 COLLISION!
      +----+     h(1239, 4) = ((9 + 4*4) mod 10) = (9 + 16) mod 10 = 5
    9 |9769|
      +----+  h(4584, 0) = 4 + 0 = 4
    


next up previous
Next: Analysis of Open Addressing Up: l5 Previous: Double Hashing