SEO-Optimized 40-Character Title on Hashing Algorithms
1.
2. Sequential search requires, on the average O(n)
Binary search requires much fewer comparisons on the average O (log
n)
There is another widely used technique for storing of data called
HASHING. It does away with the requirement of keeping data sorted
(as in binary search)
In its worst case, hashing algorithm starts behaving like linear search.
Best case timing behavior of searching using hashing = O( 1)
Worst case timing Behavior of searching using hashing = O(n)
In hashing, the record for a key value "key", is directly referred by
calculating the address.
Address or location of an element or record, x, is obtained by
computing some arithmetic function f. f(key) gives the address of x in
the table.
3.
4. There are two different forms of hashing.
Open hashing or external hashing
◦ Open or external hashing, allows records to be stored in
unlimited space (could be a hard disk). It places no limitation
on the size of the tables.
Close hashing or internal hashing
◦ Closed or internal hashing, uses a fixed space for storage and
thus limits the size of hash table.
5. The basic idea is that the records [elements] are
partitioned into B classes, numbered 0,1,2 … B‐l
A Hashing function f(x) maps a record with key n to an
integer value between 0 and B‐l.
Each bucket in the bucket table is the head of the linked list of
records mapped to that bucket.
6.
7. A closed hash table keeps the elements in the bucket
itself.
Only one element can be put in the bucket
If we try to place an element in the bucket f(n) and find
it already holds an element, then we say that a collision
has occurred.
In closed hashing, collision handling is a very
important issue.
8. Characteristics of a Good Hash Function
◦ A good hash function avoids collisions.
◦ A good hash function tends to spread keys evenly in the
array.
◦ A good hash function is easy to compute.
◦ A good hash function should be quick.
10. In this method we use modular arithmetic system to divide the key value by
some integer divisor m (may be table size).
It gives us the location value, where the element can be placed.
We can write,
L = (K mod m) + 1
where L => location in table/file K => key value
m => table size/number of slots in file
Suppose, k = 23, m = 10 then
L = (23 mod 10) + 1= 3 + 1=4, The key whose value is 23 is placed in
4th location.
11. In this case, we square the value of a key and take the
number of digits required to form an address, from
the middle position of squared value.
Suppose a key value is 16, then its square is 256.
Now if we want address of two digits, then you select
the address as 56 (i.e. two digits starting from middle
of 256).
12. combine the various parts of the key in such a
way that all parts of the key affect for final result
such an operation is termed folding of the key.
That is the key is actually partitioned into number
of parts, each part having the same length as that
of the required address.
Add the value of each parts, ignoring the final
carry to get the required address.
13. Fold‐shifting: Here actual values of each parts of key are added.
Suppose, the key is : 12345678, and the required address is of
two digits, Then break the key into: 12, 34, 56, 78.
Add these, we get 12 + 34 + 56 + 78 : 180, ignore first 1 we
get 80 as location
Fold‐boundary: Here the reversed values of outer parts of key
are added.
Suppose, the key is : 12345678, and the required address is of
two digits, Then break the key into: 21, 34, 56, 87.
Add these, we get 21 + 34 + 56 + 87 : 198, ignore first 1 we
get 98 as location
14. This hashing function is a distribution dependent.
Here we make a statistical analysis of digits of the key, and
select those digits (of fixed position) which occur quite
frequently.
Then reverse or shifts the digits to get the address.
For example, if the key is : 9861234. If the statistical analysis
has revealed the fact that the third and fifth position digits
occur quite frequently, then we choose the digits in these
positions from the key. So we get, 62. Reversing it we get 26
as the address.
15. In this type of hashing function we use the length of the key
along with some portion of the key j to produce the address,
directly.
In the indirect method, the length of the key along with some
portion of the key is used to obtain intermediate value.
16. Here a n bit key value is represented as a polynomial.
The divisor polynomial is then constructed based on the
address range required.
The modular division of key‐polynomial by divisor
polynomial, to get the address‐polynomial.
Let f(x) = polynomial of n bit key = a1 + a2x + ……. + anxn‐1
d(x) = divisor polynomial = x1 + d1 + d2x + …. + d1x1‐1
then the required address polynomial will be f(x) mod d(x)
17. This method is based on obtaining an address of a key,
based on the multiplication value.
If k is the non‐negative key, and a constant c, (0 < c <
1), compute kc mod 1, which is a fractional part of kc.
Multiply this fractional part by m and take a floor value
to get the address
H(k)= | m (kc mode 1) |
0<H(k)<m