2 random the distribution is random in the average

Info icon This preview shows pages 48–50. Sign up to view the full content.

View Full Document Right Arrow Icon
2. Random: The distribution is random. In the average case, each bucket will have nearly the same number of values assigned to it regardless of the actual distribution of the search-key values. More precisely, the hash value will not be correlated to any externally visible ordering on the search-key values, such as alphabetic ordering or ordering by the length of the search keys; the hash function will appear to be random. Some Examples Illustrating These Qualities Example 1: Suppose we have 26 buckets, and map branch-names of account file beginning with i th letter of the alphabet to the i th bucket. Problem: This does not give uniform distribution. Many more names will be mapped to “B” and “R" than to “Q” and “X”. Example 2: Suppose we have 10 buckets, and a hash function to map search-key balance of account file. Supposing min and max values to be 1 and 100,000, we can use a hash function that divides the values into 10 ranges: 1 – 10,000, 10,001 – 20,000, …, 90,001 – 100,000. Problem: The distribution is not random. It’s also not uniform as balances between 1 and 10,000 are far more common than are records with balances between 90,001 and 100,000. How Hash Functions Should be Designed Hash functions require careful design. A bad hash function may result in lookup taking time proportional to the number of search keys in the file. A well-designed function gives an average- case lookup time that is a small constant independent of the number of search-keys in the file. Typical hash functions perform some operation on the internal binary machine representations of characters in the search-key. For example, for a string search-key, the binary representations of all the characters in the string could be added and the sum modulo number of buckets could be returned. The figure beside shows the application of such a scheme, with 10 buckets, to the account file, under the assumption that the i th letter in the alphabet is represented by the integer i . Handling of Bucket Overflows So far, we have assumed that, when a record is inserted, the bucket to which it is mapped has space to store the record. If the bucket does not have enough space, a bucket overflow is said to occur. Figure: Typical application of a hash function scheme.
Image of page 48

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
45 Causes of bucket overflows 1. Insufficient buckets. Our estimate of the number of records that the relation will have was too low, and hence the number of buckets allotted was not sufficient. 2. Skew. Some buckets are assigned more records than are others, so a bucket may overflow even when other buckets still have space. This situation is called bucket skew . Causes of Skew 1. Multiple records may have the same search key. 2. The chosen hash function may result in non-uniform distribution of search keys. Reducing bucket overflows To reduce the occurrence of overflows, we can: 1. Choose the hash function more carefully, and make better estimates of the relation size.
Image of page 49
Image of page 50
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern