Presentation is loading. Please wait.

Presentation is loading. Please wait.

Rehashing Techniques When collision occur, how do we resolve the problem???? 1Prepared by Perla P. Cosme.

Similar presentations


Presentation on theme: "Rehashing Techniques When collision occur, how do we resolve the problem???? 1Prepared by Perla P. Cosme."— Presentation transcript:

1 Rehashing Techniques When collision occur, how do we resolve the problem???? 1Prepared by Perla P. Cosme

2 Topic Outline 1.Addressing Techniques b.Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing c.Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree c.Address Calculation or Hashing 2.Address Calculation 3.Rehashing Strategies 2 Prepared by: Perla P. Cosme

3 Rehashing Techniques 1.Linear Probing 2.Two-Pass File Creation 3.Separate Overflow Area 4.Double Hashing 5.Synonym Chaining 6.Bucket Addressing 7.Bucket Chaining Prepared by: Perla P. Cosme3

4 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. Cosme4

5 Preliminaries These words were subjected to a hashing function to get their relative positions. The hash(ing) function is described as follows: 1.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. 2.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 (b 4 b 3 b 2 b 1 b 0 ) (Why?) 3.Apply XOR operation to binary numbers of the word. 4.The result is converted into its decimal equivalent. The decimal number is the relative position. Prepared by Perla P. Cosme5

6 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) = xor xor = = Prepared by Perla P. Cosme6

7 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. Cosme7

8 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. Cosme8

9 Table 1. Relative addresses of the Hashed word Prepared by Perla P. Cosme9 WORDHash(WORD)WORDHash(WORD)WORD Hash(WORD) THE25IT29NOT21 OF9*WITH2NO1 AND11AS18TON21 TO27HIS18SAYS24 A1ON1ARE22 IN7BE7BUT3 THAT9*AT21FROM22 IS26BY27OR29 WAS5I9HAVE26 HE13THIS6AN15 FOR27HAD13THEY0

10 Some Notes About Table 1 1.The relative positions generated from the hash function ranges from only. (why?) 2.The results or the relative positions creates a lot of collisions – best example to handle collision. Prepared by Perla P. Cosme10

11 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. Cosme11

12 Rehashing Techniques 1.Linear Probing 2.Two-Pass File 3.Separate Overflow Area 4.Double Hashing 5.Synonym Chaining 6.Bucket Addressing 7.Bucket Chaining Prepared by: Perla P. Cosme12

13 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. Cosme13

14 Rehashing Techniques 1.Linear Probing 2.Two-Pass File Creation 3.Separate Overflow Area 4.Double Hashing 5.Synonym Chaining 6.Bucket Addressing 7.Bucket Chaining Prepared by: Perla P. Cosme14

15 Rehashing Techniques 1.Linear Probing 2.Two-Pass File Creation 3.Separate Overflow Area 4.Double Hashing 5.Synonym Chaining 6.Bucket Addressing 7.Bucket Chaining Prepared by: Perla P. Cosme15

16 Rehashing Techniques 1.Linear Probing 2.Two-Pass File Creation 3.Separate Overflow Area 4.Double Hashing 5.Synonym Chaining 6.Bucket Addressing 7.Bucket Chaining Prepared by: Perla P. Cosme16

17 Rehashing Techniques 1.Linear Probing 2.Two-Pass File Creation 3.Separate Overflow Area 4.Double Hashing 5.Synonym Chaining 6.Bucket Addressing 7.Bucket Chaining Prepared by: Perla P. Cosme17

18 Rehashing Techniques 1.Linear Probing 2.Two-Pass File Creation 3.Separate Overflow Area 4.Double Hashing 5.Synonym Chaining 6.Bucket Addressing 7.Bucket Chaining Prepared by: Perla P. Cosme18

19 Rehashing Techniques 1.Linear Probing 2.Two-Pass File Creation 3.Separate Overflow Area 4.Double Hashing 5.Synonym Chaining 6.Bucket Addressing 7.Bucket Chaining Prepared by: Perla P. Cosme19


Download ppt "Rehashing Techniques When collision occur, how do we resolve the problem???? 1Prepared by Perla P. Cosme."

Similar presentations


Ads by Google