CS 70
Discrete Mathematics and Probability Theory
Fall 2010
Tse/Wagner
Soln 9
1. (16 pts.)
A Very Small Example of Hashing
Suppose we hash three objects randomly into a table with three (labelled) entries. We are interested in the
lengths of the linked lists at the three table entries.
(a) List all the outcomes in the sample space of the experiment. How many of them are there?
Answer 1:
The outcomes are
Ω
=
(
1
,
1
,
1
)
(
1
,
1
,
2
)
(
1
,
1
,
3
)
(
1
,
2
,
1
)
(
1
,
2
,
2
)
(
1
,
2
,
3
)
(
1
,
3
,
1
)
(
1
,
3
,
2
)
(
1
,
3
,
3
)
(
2
,
1
,
1
)
(
2
,
1
,
2
)
(
2
,
1
,
3
)
(
2
,
2
,
1
)
(
2
,
2
,
2
)
(
2
,
2
,
3
)
(
2
,
3
,
1
)
(
2
,
3
,
2
)
(
2
,
3
,
3
)
(
3
,
1
,
1
)
(
3
,
1
,
2
)
(
3
,
1
,
3
)
(
3
,
2
,
1
)
(
3
,
2
,
2
)
(
3
,
2
,
3
)
(
3
,
3
,
1
)
(
3
,
3
,
2
)
(
3
,
3
,
3
)
where
(
a
1
,
a
2
,
a
3
)
means that the
i
th object is hashed to table entry
a
i
. There are 27 outcomes.
Answer 2:
The set of outcomes of this experiment is
Ω
=
{
(
a
1
,
a
2
,
a
3
)
:
a
1
,
a
2
,
a
3
∈ {
1
,
2
,
3
}}
, where
a
i
denotes the table entry/bucket where object
i
is hashed to. Hence,

Ω

=
3
×
3
×
3
=
27.
Answer 3:
We can create a different sample space
Ω
0
from the first answer, by tracking how many
objects get hashed to each table entry/bucket. So now,
Ω
0
=
{
(
b
1
,
b
2
,
b
3
)
:
b
i
∈ {
0
,
1
,
2
,
3
}
,
b
1
+
b
2
+
b
3
=
3
}
, where
b
i
denotes the number of objects that are hashed to table entry/bucket
i
. More explicitly,
Ω
0
=
(
0
,
0
,
3
)
(
1
,
1
,
1
)
(
0
,
1
,
2
)
(
1
,
2
,
0
)
(
0
,
2
,
1
)
(
2
,
0
,
1
)
(
0
,
3
,
0
)
(
2
,
1
,
0
)
(
1
,
0
,
2
)
(
3
,
0
,
0
)
There are 10 outcomes.
Comment:
In Answers 1 and 2, we have Pr
[
ω
] =
1

Ω

=
1
27
. for all
ω
∈
Ω
. Therefore, the probability
space for Answers 1 and 2 is uniform.
In contrast, the probability assignment for Answer 3 is not uniform. The probabilities are no longer
the same for all
ω
∈
Ω
0
. For example, Pr
[(
1
,
1
,
1
)] =
6
27
since any of the 3!
=
6 ways of permuting the
three objects among the three table entries would contribute a probability of
(
1
3
)
3
=
1
27
to Pr
[(
1
,
1
,
1
)]
.
Similarly, Pr
[(
1
,
2
,
0
)] =
3
27
since there are
(
3
1
)
ways of choosing which of the three objects gets hashed
CS 70, Fall 2010, Soln 9
1