09.12.2012 Views

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8.5 HASHING 409<br />

When such “coincidences” occur, we suspect that there’s a mathematical<br />

reason; there might be another way to attack the problem, explaining why<br />

the answer has such a simple <strong>for</strong>m. And indeed, there is another approach (in<br />

exercise 60), which shows that the variance of the average successful search<br />

has the general <strong>for</strong>m<br />

VA =<br />

k=l<br />

(8.103)<br />

when sk is the probability that the kth-inserted element is being sought.<br />

Equation (8.102) is the special case sk = l/n <strong>for</strong> 1 < k 6 n.<br />

Besides the variance of the average, we might also consider the average of<br />

the variance. In other words, each sequence (hl , . . . , hn) that defines a hash<br />

table also defines a probability distribution <strong>for</strong> successful searching, and the<br />

variance of this probability distribution tells how spread out the number of<br />

probes will be in different successful searches. For example, let’s go back to<br />

Where have 1 seen the case where we inserted n = 16 things into m = 10 lists:<br />

that pattern be<strong>for</strong>e?<br />

Where have 1 seen h , . . . ,h16)=3 141592653589793<br />

that grafito be<strong>for</strong>e?<br />

IqvP, .<br />

Pl, * *.,P,6)=1112111122312133<br />

A successful search in the resulting hash table has the pgf<br />

G(3,1,4,1,... ,3) = f SkZP(3,1,4,1,...,3;k)<br />

k=l<br />

= SlZ+S2Z+S3Z+S4Z2+...+S~~Z3.<br />

We have just considered the average number of probes in a successful search<br />

of this table, namely A(3,1,4,1,. . . ,3) = Mean(G(3,1,4,1,. . . ,3)). We can<br />

also consider the variance,<br />

This variance is a random variable, depending on (hl , . . . , h,), so it is natural<br />

to consider its average value.<br />

In other words, there are three natural kinds of variance that we may<br />

wish to know, in order to understand the behavior of a successful search: The<br />

overuZZ variance of the number of probes, taken over all (h1,. , . , h,,) and k;<br />

the variance of the average number of probes, where the average is taken<br />

over all k and the variance is then taken over all (h, , . . . , h,,); and the average<br />

of the variance of the number of the probes, where the variance is taken over

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!