280 likes | 1k Views
Rehashing Techniques. When collision occur, how do we resolve the problem????. Topic Outline. Addressing Techniques Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree
E N D
Rehashing Techniques When collision occur, how do we resolve the problem???? Prepared by Perla P. Cosme
Topic Outline • Addressing Techniques • Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing • Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree • Address Calculation or Hashing • Address Calculation • Rehashing Strategies Prepared by: Perla P. Cosme
Rehashing Techniques • Linear Probing • Two-Pass File Creation • Separate Overflow Area • Double Hashing • Synonym Chaining • Bucket Addressing • Bucket Chaining Prepared by: Perla P. Cosme
Preliminaries To illustrate how each of the different rehashing techniques work, we shall apply these rehashing techniques to a group of words (the words the primary keys). Note: Primary keys need not, be an integer at all times; it may also of character data type. Prepared by Perla P. Cosme
Preliminaries These words were subjected to a hashing function to get their relative positions. The hash(ing) function is described as follows: • Take the ASCII value of each letter in the word. The ASCII table maybe found in almost any Computer Science or IT book; usually found in the appendix. Or, simply download one from the internet. • If not available in the ASCII table, convert the decimal equivalent of the letter into its binary form. Consider only the first 5 significant bits (b4b3b2b1b0) (Why?) • Apply XOR operation to binary numbers of the word. • The result is converted into its decimal equivalent. The decimal number is the relative position. Prepared by Perla P. Cosme
An Example Let the word to be hashed is THE. Then, relative position of the primary key, THE is 25. hash(THE) = ASCII(T) xor ASCII(H) xor ASCII(E) = 101002xor 010002xor 001012 = 110012 = 2510 Prepared by Perla P. Cosme
Let’s try this … Question: Using the same hash function, what would be the relative position of the word OF? Answer: 9 (How did we get the answer?) Prepared by Perla P. Cosme
Hash Function Description If we do the same process (or hashing all the words) to some common words such as those on Table 1, then, we can complete their relative positions, too. (see Table 1 – next slide, please). Prepared by Perla P. Cosme
Table 1. Relative addresses of the Hashed word Prepared by Perla P. Cosme
Some Notes About Table 1 • The relative positions generated from the hash function ranges from 0..29 only. (why?) • The results or the relative positions creates a lot of collisions – best example to handle collision. Prepared by Perla P. Cosme
From this time thereon, we shall refer to Table 1 to illustrate how the different rehashing techniques work. Advise: Keep a copy of the table close to you as we illustrate the rehashing technique. Prepared by Perla P. Cosme
Rehashing Techniques • Linear Probing • Two-Pass File • Separate Overflow Area • Double Hashing • Synonym Chaining • Bucket Addressing • Bucket Chaining Prepared by: Perla P. Cosme
Question How do we handle collisions given the values in Table 1 using Linear Probing Technique? Answer: (Please refer to the board on how the collisions are handled.) Prepared by Perla P. Cosme
Rehashing Techniques • Linear Probing • Two-Pass File Creation • Separate Overflow Area • Double Hashing • Synonym Chaining • Bucket Addressing • Bucket Chaining Prepared by: Perla P. Cosme
Rehashing Techniques • Linear Probing • Two-Pass File Creation • Separate Overflow Area • Double Hashing • Synonym Chaining • Bucket Addressing • Bucket Chaining Prepared by: Perla P. Cosme
Rehashing Techniques • Linear Probing • Two-Pass File Creation • Separate Overflow Area • Double Hashing • Synonym Chaining • Bucket Addressing • Bucket Chaining Prepared by: Perla P. Cosme
Rehashing Techniques • Linear Probing • Two-Pass File Creation • Separate Overflow Area • Double Hashing • Synonym Chaining • Bucket Addressing • Bucket Chaining Prepared by: Perla P. Cosme
Rehashing Techniques • Linear Probing • Two-Pass File Creation • Separate Overflow Area • Double Hashing • Synonym Chaining • Bucket Addressing • Bucket Chaining Prepared by: Perla P. Cosme
Rehashing Techniques • Linear Probing • Two-Pass File Creation • Separate Overflow Area • Double Hashing • Synonym Chaining • Bucket Addressing • Bucket Chaining Prepared by: Perla P. Cosme