<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
dynamic	B-Algorithm
perfect	I-Algorithm
hashing	I-Algorithm
is	O
a	O
programming	O
technique	O
for	O
resolving	O
collisions	B-Algorithm
in	O
a	O
hash	B-Algorithm
table	I-Algorithm
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
While	O
more	O
memory-intensive	O
than	O
its	O
hash	B-Algorithm
table	I-Algorithm
counterparts	O
,	O
this	O
technique	O
is	O
useful	O
for	O
situations	O
where	O
fast	O
queries	O
,	O
insertions	O
,	O
and	O
deletions	O
must	O
be	O
made	O
on	O
a	O
large	O
set	O
of	O
elements	O
.	O
</s>
<s>
The	O
problem	O
of	O
optimal	O
static	B-Algorithm
hashing	I-Algorithm
was	O
first	O
solved	O
in	O
general	O
by	O
Fredman	O
,	O
Komlós	O
and	O
Szemerédi	O
.	O
</s>
<s>
In	O
their	O
1984	O
paper	O
,	O
they	O
detail	O
a	O
two-tiered	O
hash	B-Algorithm
table	I-Algorithm
scheme	O
in	O
which	O
each	O
bucket	O
of	O
the	O
(	O
first-level	O
)	O
hash	B-Algorithm
table	I-Algorithm
corresponds	O
to	O
a	O
separate	O
second-level	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
Keys	O
are	O
hashed	O
twice	O
—	O
the	O
first	O
hash	B-Error_Name
value	I-Error_Name
maps	O
to	O
a	O
certain	O
bucket	O
in	O
the	O
first-level	O
hash	B-Algorithm
table	I-Algorithm
;	O
the	O
second	O
hash	B-Error_Name
value	I-Error_Name
gives	O
the	O
position	O
of	O
that	O
entry	O
in	O
that	O
bucket	O
's	O
second-level	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
perfect	B-Algorithm
hashing	I-Algorithm
)	O
upon	O
construction	O
.	O
</s>
<s>
Consequently	O
,	O
the	O
look-up	O
cost	O
is	O
guaranteed	O
to	O
be	O
O(1 )	O
in	B-General_Concept
the	I-General_Concept
worst-case	I-General_Concept
.	O
</s>
<s>
Fredman	O
,	O
Komlós	O
and	O
Szemerédi	O
pick	O
a	O
first-level	O
hash	B-Algorithm
table	I-Algorithm
with	O
size	O
buckets	O
.	O
</s>
<s>
To	O
construct	O
,	O
entries	O
are	O
separated	O
into	O
buckets	O
by	O
the	O
top-level	O
hashing	B-Error_Name
function	I-Error_Name
,	O
where	O
.	O
</s>
<s>
Then	O
for	O
each	O
bucket	O
with	O
entries	O
,	O
a	O
second-level	O
table	O
is	O
allocated	O
with	O
slots	O
,	O
and	O
its	O
hash	B-Error_Name
function	I-Error_Name
is	O
selected	O
at	O
random	O
from	O
a	O
universal	B-Algorithm
hash	I-Algorithm
function	I-Algorithm
set	O
so	O
that	O
it	O
is	O
collision-free	O
(	O
i.e.	O
</s>
<s>
a	O
perfect	B-Algorithm
hash	I-Algorithm
function	I-Algorithm
)	O
and	O
stored	O
alongside	O
the	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
If	O
the	O
hash	B-Error_Name
function	I-Error_Name
randomly	O
selected	O
creates	O
a	O
table	O
with	O
collisions	B-Algorithm
,	O
a	O
new	O
hash	B-Error_Name
function	I-Error_Name
is	O
randomly	O
selected	O
until	O
a	O
collision-free	O
table	O
can	O
be	O
guaranteed	O
.	O
</s>
<s>
Finally	O
,	O
with	O
the	O
collision-free	O
hash	B-Error_Name
,	O
the	O
entries	O
are	O
hashed	O
into	O
the	O
second-level	O
table	O
.	O
</s>
<s>
The	O
quadratic	O
size	O
of	O
the	O
space	O
ensures	O
that	O
randomly	O
creating	O
a	O
table	O
with	O
collisions	B-Algorithm
is	O
infrequent	O
and	O
independent	O
of	O
the	O
size	O
of	O
,	O
providing	O
linear	O
amortized	B-General_Concept
construction	O
time	O
.	O
</s>
<s>
Although	O
each	O
second-level	O
table	O
requires	O
quadratic	O
space	O
,	O
if	O
the	O
keys	O
inserted	O
into	O
the	O
first-level	O
hash	B-Algorithm
table	I-Algorithm
are	O
uniformly	O
distributed	O
,	O
the	O
structure	O
as	O
a	O
whole	O
occupies	O
expected	O
space	O
,	O
since	O
bucket	O
sizes	O
are	O
small	O
with	O
high	O
probability	O
.	O
</s>
<s>
The	O
first-level	O
hash	B-Error_Name
function	I-Error_Name
is	O
specifically	O
chosen	O
so	O
that	O
,	O
for	O
the	O
specific	O
set	O
of	O
unique	O
key	O
values	O
,	O
the	O
total	O
space	O
used	O
by	O
all	O
the	O
second-level	O
hash	B-Algorithm
tables	I-Algorithm
has	O
expected	O
space	O
,	O
and	O
more	O
specifically	O
.	O
</s>
<s>
Fredman	O
,	O
Komlós	O
and	O
Szemerédi	O
showed	O
that	O
given	O
a	O
universal	B-Algorithm
hashing	I-Algorithm
family	O
of	O
hash	B-Error_Name
functions	I-Error_Name
,	O
at	O
least	O
half	O
of	O
those	O
functions	O
have	O
that	O
property	O
.	O
</s>
<s>
present	O
a	O
dynamic	O
dictionary	O
algorithm	O
that	O
,	O
when	O
a	O
set	O
of	O
n	O
items	O
is	O
incrementally	O
added	O
to	O
the	O
dictionary	O
,	O
membership	O
queries	O
always	O
run	O
in	O
constant	O
time	O
and	O
therefore	O
worst-case	O
time	O
,	O
the	O
total	O
storage	O
required	O
is	O
(	O
linear	O
)	O
,	O
and	O
expected	O
amortized	B-General_Concept
insertion	O
and	O
deletion	O
time	O
(	O
amortized	B-General_Concept
constant	I-General_Concept
time	I-General_Concept
)	O
.	O
</s>
<s>
In	O
the	O
dynamic	O
case	O
,	O
when	O
a	O
key	O
is	O
inserted	O
into	O
the	O
hash	B-Algorithm
table	I-Algorithm
,	O
if	O
its	O
entry	O
in	O
its	O
respective	O
subtable	O
is	O
occupied	O
,	O
then	O
a	O
collision	O
is	O
said	O
to	O
occur	O
and	O
the	O
subtable	O
is	O
rebuilt	O
based	O
on	O
its	O
new	O
total	O
entry	O
count	O
and	O
randomly	O
selected	O
hash	B-Error_Name
function	I-Error_Name
.	O
</s>
<s>
Because	O
the	O
load	O
factor	O
of	O
the	O
second-level	O
table	O
is	O
kept	O
low	O
,	O
rebuilding	O
is	O
infrequent	O
,	O
and	O
the	O
amortized	B-General_Concept
expected	O
cost	O
of	O
insertions	O
is	O
.	O
</s>
<s>
Similarly	O
,	O
the	O
amortized	B-General_Concept
expected	O
cost	O
of	O
deletions	O
is	O
.	O
</s>
<s>
By	O
results	O
due	O
to	O
Dietzfelbinger	O
et	O
al.	O
,	O
as	O
long	O
as	O
the	O
total	O
number	O
of	O
insertions	O
or	O
deletions	O
exceeds	O
the	O
number	O
of	O
elements	O
at	O
the	O
time	O
of	O
last	O
construction	O
,	O
the	O
amortized	B-General_Concept
expected	O
cost	O
of	O
insertion	O
and	O
deletion	O
remain	O
with	O
full	O
rehashing	O
taken	O
into	O
consideration	O
.	O
</s>
<s>
The	O
implementation	O
of	O
dynamic	B-Algorithm
perfect	I-Algorithm
hashing	I-Algorithm
by	O
Dietzfelbinger	O
et	O
al	O
.	O
</s>
<s>
uses	O
these	O
concepts	O
,	O
as	O
well	O
as	O
lazy	B-Algorithm
deletion	I-Algorithm
,	O
and	O
is	O
shown	O
in	O
pseudocode	O
below	O
.	O
</s>
<s>
If	O
x	O
exists	O
at	O
j	O
or	O
at	O
the	O
subtable	O
Tj	O
,	O
and	O
is	O
not	O
marked	O
as	O
deleted	O
,	O
then	O
a	O
collision	O
is	O
said	O
to	O
occur	O
and	O
the	O
jth	O
bucket	O
's	O
second-level	O
table	O
Tj	O
is	O
rebuilt	O
with	O
a	O
different	O
randomly	O
selected	O
hash	B-Error_Name
function	I-Error_Name
hj	O
.	O
</s>
<s>
A	O
full	O
rebuild	O
of	O
the	O
table	O
of	O
S	O
first	O
starts	O
by	O
removing	O
all	O
elements	O
marked	O
as	O
deleted	O
and	O
then	O
setting	O
the	O
next	O
threshold	O
value	O
M	O
to	O
some	O
constant	O
multiple	O
of	O
the	O
size	O
of	O
S	O
.	O
A	O
hash	B-Error_Name
function	I-Error_Name
,	O
which	O
partitions	O
S	O
into	O
s(M )	O
subsets	O
,	O
where	O
the	O
size	O
of	O
subset	O
j	O
is	O
sj	O
,	O
is	O
repeatedly	O
randomly	O
chosen	O
until	O
:	O
</s>
<s>
Finally	O
,	O
for	O
each	O
subtable	O
Tj	O
a	O
hash	B-Error_Name
function	I-Error_Name
hj	O
is	O
repeatedly	O
randomly	O
chosen	O
from	O
Hsj	O
until	O
hj	O
is	O
injective	O
on	O
the	O
elements	O
of	O
Tj	O
.	O
</s>
