+ All Categories
Home > Documents > Alqrainy's Function to minimize the collision of hashing

Alqrainy's Function to minimize the collision of hashing

Date post: 15-Nov-2014
Category:
Upload: ramzi-alqrainy
View: 105 times
Download: 0 times
Share this document with a friend
11

Click here to load reader

Transcript
Page 1: Alqrainy's Function to minimize the collision of hashing

1 | P a g e

HASHING

Prepared by : Ramzi Alqrainy

[email protected]

[email protected]

Hashing 2

Designing hash functions 3

Analysis of Hashing Method 7

Implementation of Alqrainy`s Function 8

Page 2: Alqrainy's Function to minimize the collision of hashing

2 | P a g e

HASHING

HASHING

A Hash function is any well-defined procedure or mathematical function which converts a large, possibly variable-sized amount of data into a small datum, usually a single integer that may serve as an index into an array. The values returned by a hash function are called hash values, hash codes, hash sums, or simply hashes.

Hash functions are mostly used to speed up table lookup or data comparison tasks —such as finding items in a database, detecting duplicated or similar records in a large file, finding similar stretches in DNA sequences, and so on.

The basic idea in hashing is to take a field in a record, known as the key, and convert it through some fixed process (Hashing Function) to a numeric value (Hash Value) in the range of 0…m-1 , where m is the table size.

Page 3: Alqrainy's Function to minimize the collision of hashing

3 | P a g e

HASHING

Designing hash functions *

A good has function satisfies the assumption of simple uniform hashing: eachkey is equally likely to hash to any of the m slots, independently of where anyother key has hashed to.

* Hashing By Division

* Hashing By Multiplication

* Hashing By Mid-Square

* The division method

The division method involves mapping k into the ith slot where i is the remainderwhen k is divided by the number of slots, m. That is, the hash function is:

h(k) = k mod m

With these conventions, let us write a method in C++ to hash the key and returning a

hash value by division method. (*)

* This code is a part from "Ramzi Code" in page 7

Page 4: Alqrainy's Function to minimize the collision of hashing

4 | P a g e

HASHING

* The multiplication method

The multiplication method for creating hash functions operates in two steps.

1.Multiply the key k by a constant A in the range 0 < A < 1 and extract the fractional part of kA.2. Multiply this value by m and take the floor of the result.In short the hash function is:

* The Mid-Square Method

The key K is squared, then the hash function h is defined by:

h(k)=L

Where L is obtained by deleting digits from both ends of k2

Page 5: Alqrainy's Function to minimize the collision of hashing

5 | P a g e

HASHING

** Alqrainy`s function

In this assignment, I have developed my own function (called "Alqrainy's function") to minimize the collision when using Hashing table. Fig-1 describes Alqrainy's function.

Alqrainy(k)=[k+(hash_size*3)/7] mod hash_size

Fig-1

Where k = key, hash_size = hash table size.

Page 6: Alqrainy's Function to minimize the collision of hashing

6 | P a g e

HASHING

In order to give a picture of number of collision , five experiments have been done

using four methods. These methods are (Division, Multiplication,Mid-Sqaure , Alqrainy), the results of the experiments are shown in figure-2

This code to generate the distinct random number.

Page 7: Alqrainy's Function to minimize the collision of hashing

7 | P a g e

HASHING

* Analysis of Hashing Method

0 20 40 60 80

exp1

exp2

exp3

exp4

exp5Alqrainy

Mid-Square

Multiplication

Division

Alqrainy 52 55 62 65 59

Mid-Square 68 71 65 72 68

Multiplication 57 62 67 71 58

Division 63 56 64 65 57

exp1 exp2 exp3 exp4 exp5

ffFig-2

As shown in figure 2 the relationship between the Alqrainy's function and the number of the collision has achieved good result a mong other methods

The code of the Alqrainy's function is described below.

Page 8: Alqrainy's Function to minimize the collision of hashing

8 | P a g e

HASHING

Implementation of Alqrainy`s Function in C++

Page 9: Alqrainy's Function to minimize the collision of hashing

9 | P a g e

HASHING

Page 10: Alqrainy's Function to minimize the collision of hashing

10 | P a g e

HASHING

Page 11: Alqrainy's Function to minimize the collision of hashing

11 | P a g e

HASHING


Recommended