Documente Academic
Documente Profesional
Documente Cultură
Load Factor
To analyze efficiency of hashing we use the
load factor, , which is the average number
of elements in a slot. This is a quantity that
changes over time as the table acquires or
loses elements.
What is the load factor of an
m-slot hash table holding q
objects?
Universal Hashing
Suppose that a situation in which an
application that employs hashing is repeatedly
executed and in which the hash function is
selected from a pool of hash functions at
each execution.
Let H be the pool of hash functions.
We say that H is universal if, for all keys x
and y, x 6= y, it holds that
kHk
hH
yS,x6=y (h, x, y)
kHk
where (h, x, y) = 1 if h(x) = h(y) and 0
otherwise. This quantity is equal to
P
yS,x6=y
hH (h, x, y)
kHk
By (*), this is
m1
1
< 1.
m
m
yS,x6=y
X
12
13
(mod p)
s = (al + b)
(mod p)
r s = a(k l)
(mod p)
r 6= s
Furthermore we can solve for a and b:
a = ((r s)((k l)1
b = (r ak)
(mod p)))
(mod p)
(mod p)
(p + m 1)
1
m
= (p 1)/m
dp/me 1
(p 1)/m
p1
= 1/m
P r{r = s mod m}
15
Open Addressing
Open addressing is an alternative to chaining,
where collision is resolved by putting the
element into an open slot.
To do this we assign to each key a sequence
of addresses to search for an open slot.
Formally, we extend the hash function to one
that takes two inputs, namely a mapping
from U Zm to Zm, where for each k U the
slots h(k, 0), . . . , h(k, m 1) are examined in
this order and the first open one is used to
store k. The sequence
hh(k, 0), . . . , h(k, m 1)i is called the probe
sequence for k. We design that each probe
sequence is a permutation of Zm.
16
17
18
(mod m).
19
Primary clustering
Primary clustering is a situation in which
there is a long line of occupied slots. Primary
clustering is observed typically in linear
probing
In linear probing, if every other slot is
occupied, then the average unsuccessful
search takes 1.5 probes. On the other hand,
if there is a cluster of one half of the slots,
then the average number of probes is
m/2
X
1 m
1 m m
m 3
1
+
+1 = + .
i = +
m 2
2 2m 2 2
8 4
i=1
20
22
i=1
ipi =
n
X
qi .
i=1
Note that
n
qi =
m
= i.
i
n1
ni+1
n
m1
mi+1
m
i=1
i=0
1
23