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.

400 DISCRETE PROBABILITY<br />

Thus the main quantity that governs the running time of the search procedure<br />

is the number of probes, P.<br />

We can get a good mental picture of the algorithm by imagining that we<br />

are keeping an address book that is organized in a special way, with room <strong>for</strong><br />

only one entry per page. On the cover of the book we note down the page<br />

number <strong>for</strong> the first entry in each of m lists; each name K determines the list<br />

h(K) that it belongs to. Every page inside the book refers to the successor<br />

page in its list. The number of probes needed to find an address in such a<br />

book is the number of pages we must consult.<br />

If n items have been inserted, their positions in the table depend only<br />

on their respective hash val.ues, (h’ , hz, . . . , &). Each of the m” possible<br />

sequences (h’ , h2, . . . , &) is considered to be equally likely, and P is a random<br />

variable depending on such a sequence.<br />

Case 1: The key is not present. Check under the<br />

Let’s consider first the behavior of P in an unsuccessful search, assuming doormat.<br />

that n records have previously been inserted into the hash table. In this case<br />

the relevant probability spac:e consists of mn+’ elementary events<br />

w = (h’,hz,...,h,;hT,+‘)<br />

where b is the hash value of the jth key inserted, and where &+’ is the hash<br />

value of the key <strong>for</strong> which the search is unsuccessful. We assume that the<br />

hash function h has been chosen properly so that Pr(w) = 1 /mnf’ <strong>for</strong> every<br />

such CU.<br />

For example, if m = n == 2, there are eight equally likely possibilities:<br />

hl h2 h3: P<br />

1 1 1:2<br />

11 2:o<br />

1 2 1:l<br />

1 2 2: 1<br />

2 1 1:l<br />

2 1 2:l<br />

2 2 1:o<br />

2 2 212<br />

If h’ = h2 = h3 we make two unsuccessful probes be<strong>for</strong>e concluding that the<br />

new key K is not present; if h’ = h2 # h3 we make none; and so on. This list<br />

of all possibilities shows that P has a probability distribution given by the pgf<br />

(f + $2 + $2’) = (i + iz)‘, when m = n = 2.<br />

An unsuccessful search makes one probe <strong>for</strong> every item in list number<br />

hn+‘, so we have the general <strong>for</strong>mula<br />

P = [h, =hm+,l + [hz=hn+,l + ... + [h,,=hn+ll. (8.84)

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

Saved successfully!

Ooh no, something went wrong!