11.07.2015 Views

Hash Probability - BYU Computer Science Students Homepage Index

Hash Probability - BYU Computer Science Students Homepage Index

Hash Probability - BYU Computer Science Students Homepage Index

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

we have 37 buckets with list length 1, 18 with length 2, 6 with length 3 and 2 with length 4. So, our weightedaverage is (37X1 + 18X2 + 6X3 + 2X4)/63=1.57. So, the average number of records that have to be examined tofinish an unsuccessful search is 1.57. The average number to finish a successful search is slightly less because wewouldn’t always look at every record on a list longer than 1 record.(37 + 18X1.5 + 6X2 + 2X3)/63 = 1.3We can use this same analysis to predict birthday coincidences in a room of n people. This table indicates, onaverage, how many days will be the birthday for j different people if there are n people in the room. In a group of100 people, you could expect about 10 pairs of identical birthdays, and one triple birthday.n\j 0 1.000 2.0 3 4 520 345.538 18.934 0.519 0.009 0.000 0.00023 342.710 21.595 0.680 0.014 0.000 0.00040 327.114 35.848 1.964 0.072 0.002 0.00060 309.672 50.905 4.184 0.229 0.009 0.00080 293.160 64.254 7.042 0.514 0.028 0.001100 277.529 76.035 10.416 0.951 0.065 0.004200 211.020 115.627 31.679 5.786 0.793 0.087365 134.276 134.276 67.138 22.379 5.595 1.119Collision Resolution by Open AddressingStoring records in linked lists rooted at the buckets is not the only way to handle collisions. It may be that the linkfields take a significant amount of space because the actual records are small. Another way to handle collisions is tosearch for an unused bucket and put the colliding record there. The search can be as simple as a sequential searchforward (through buckets with higher indexes). Open addressing with a simple forward search is called progressiveoverflow. For example, suppose we are going to store the following words in a hash table with 10 buckets. Also,suppose out hash function assigns the words to the given bucket address.WordBucket AddressAssigned bythe <strong>Hash</strong> Function___________________________and 5any 8bet 0big 5do 7go 8car 8As we put the words in the hash table one at a time everything is great until we try to put “big” in and find that itcollides. So we search forward and find that bucket 6 is empty so we put it there.<strong>Probability</strong> Analysis of <strong>Hash</strong>ing 6/8

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

Saved successfully!

Ooh no, something went wrong!