

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Hashing in the data structure is a technique of mapping a large chunk of data into small tables using a hashing function. It is done for faster access to elements. The efficiency of mapping depends on the efficiency of the hash function used.
hash key through the hashing algorithm is what is known as the hash value. Hash Key = Key Value % Number of Slots in the Table
fixed size, which falls into the hash table. The values returned by a hash function are called hash values, hash codes, hash sums, or simply hashes. To achieve a good hashing mechanism, It is important to have a good hash function with the following basic requirements: a. Easy to compute: It should be easy to compute and must not become an algorithm in itself. b. Uniform distribution: It should provide a uniform distribution across the hash table and should not result in clustering. c. Less collisions: Collisions occur when pairs of elements are mapped to the same hash value. These should be avoided.
The division method is the simplest and easiest method used to generate a hash value. In this hash function, the value of k is divided by M and uses the remainder as obtained. Formula- h(K) = k mod M
(where k = key value and M = the size of the hash table) Example - k = 1320 M = 11 h (1320) = 1320 mod 11 = 0
It is a situation in which the hash function returns the same hash key for more than one record, it is called as collision. The collision creates a problem because each index in a hash table is supposed to store only one value. For E.g. If using the Division method: Let’s say the array size= Then Hash(15) = 15%10 = 5 And Hash(25) = 25%10 = 5 So this hash function will return 5 as the index for both of these keys. This is called a Collision, where the resultant hashes of 2 or more Keys, wrongly map to the same place in the hash table.
Open hashing is used to avoid any hash collisions, using an array of linked lists in order to
method. Separate chaining is one of the most commonly used collision resolution techniques. It is usually implemented using linked lists. In separate chaining, each element of the hash table is a linked list. To store an element in the hash table you must insert it into a specific linked list. When two or more elements are hash to the same location, these elements are represented into a singly-linked list like a chain.
Probing technique, to find the empty cell to place this Data at, here the next slot is computed by adding the successive value of an arbitrary polynomial in the original hashed index. Quadratic probing uses a hash function of the form h(k, i) = (h' (k) + c 1 i + c 2 i 2 ) mod m where h' is an auxiliary hash function, c 1 and c 2 are positive
probed is T [h'(k)], later positions probed are offset by amounts that depend in a quadratic manner on the probe number i. ▪ Problems on quadratic probing:
such as quadratic probing to create long runs of filled slots away from the hash position of keys. If the primary hash index is x, probes go to x+1, x+4, x+9, x+16, x+ 25 and so on, this results in Secondary Clustering. Secondary clustering is less severe in terms of performance hit than primary clustering, and is an attempt to keep clusters from forming by using Quadratic Probing. The idea is to probe more widely separated cells, instead of those adjacent to the primary hash site.
for hashing with open addressing. The permutation formed by double hashing is like a random permutation therefore it almost eliminates the chances of cluster forming as it uses a secondary hash function as an offset to deal with collision condition.
29 December 2022 11: DAA Page 1
In open addressing, all entry records are stored in an array. When a new entry has to be inserted, the hash index of the hashed value is computed and then the array is examined (starting with the hashed index). If the slot at the hashed index is unoccupied, then the entry record is inserted in slot at the hashed index else it proceeds in some probe sequence until it finds an unoccupied slot. The procedure used to navigate through entries is known as the probe sequence. In Closed hashing, there are three techniques that are used to resolve the collision:
free cell is found by linearly iterating over the cells. Here, the searching is performed sequentially, starting from the position where the collision occurs till the empty cell is not found.
This method uses the hash function h(k, i)= (h'(k) + i) mod m
Problems on linear probing: probing.pdf^ linear
average search time. Clusters arise because an empty slot preceded by i full slots gets filled next with probability (i
for hashing with open addressing. The permutation formed by double hashing is like a random permutation therefore it almost eliminates the chances of cluster forming as it uses a secondary hash function as an offset to deal with collision condition. The hash function that is used in double hashing is of the form - h(k, i)= (h 1 (k) + ih 2 (k)) mod m Where both h1 and h2 are auxiliary hash functions. The initial probe goes to position T[h 1 (k)]; successive probe positions are offset from previous positions by the amount h2(k), modulo m.
DAA Page 2