# When collision occur, how do we resolve the problem????

## Presentation on theme: "When collision occur, how do we resolve the problem????"— Presentation transcript:

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

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

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

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

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

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

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
Hash(WORD) THE 25 IT 29 NOT 21 OF 9* WITH 2 NO 1 AND 11 AS 18 TON TO 27 HIS SAYS 24 A ON ARE 22 IN 7 BE BUT 3 THAT AT FROM IS 26 BY OR WAS 5 I 9 HAVE HE 13 THIS 6 AN 15 FOR HAD THEY Prepared by Perla P. Cosme

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

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

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

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

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

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

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

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

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

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