CS 280 - Data Structures


Example 1

We want to insert the following keys into our hash table: S19, P16, I9, N14, A1, L12

Our simple hash function will map the keys to indices like this:

H(S) = 5
H(P) = 2
H(I) = 2
H(N) = 0
H(A) = 1
H(L) = 5
In this example, the letters I and A collide, as well as the letters S and L. The pictures below show:
  1. After inserting S, P
  2. After inserting I
  3. After inserting N
  4. After inserting A
  5. After inserting L
The total number of probes is 8.

Notice that any letter we insert must end up in slot 4. Inserting T20, H(T) = 6, yields: this picture:


And the total number of probes is now 14.


Example 2

We want to insert the following keys into our hash table: F6, L12, E5, T20, C3, H8

Our simple hash function will map the keys to indices like this:

H(F) = 6
H(L) = 5
H(E) = 5
H(T) = 6
H(C) = 3
H(H) = 1
The picture below shows the hash table after inserting each letter:

The total probe count is 11.