- Home/
- CDS & Defence/
- Article
In which of the following hash functions, do consecutive keys map to consecutive hash values?
By BYJU'S Exam Prep
Updated on: September 25th, 2023
- Division method
- Multiplication method
- Folding method
- Mid-square method
In the division method, consecutive keys map to consecutive hash values. The hash table maps consecutive keys to successive hash values, making the division approach disadvantageous. As a result, efficiency is poor.
keys Map to Consecutive Hash Values
This is the simplest and most straightforward way to create a hash value. The value k is divided by M, and the resulting residual is used by the hash function.
Formula – h(K) = k mod M
Here,
The hash table’s size is M, and the key value is k. The fact that M is a prime number is ideal since it can ensure that the keys are distributed more evenly. The division’s remaining part is necessary for the hash function to work.
Advantages of Consecutive Hash Values:
- For any value of M, this approach works rather well.
- The division method just needs to do one division operation, hence it is very quick.
As a result, the Division approach is the appropriate response.
Mid-square method:
The address is chosen from the middle of the result after the key is squared.
Folding technique: The key is split into pieces whose dimensions correspond to those of the needed address. The address is then obtained by adding the pieces.
Method of multiplication: An irrational number multiplied by a hash function that uses the first p bits of the key.
Summary:
In which of the following hash functions, do consecutive keys map to consecutive hash values? (a) Division method (b) Multiplication method (c) Folding method (d) Mid-square method
Consecutive keys in the division method correspond to consecutive hash values. The division method is flawed because the hash table translates sequential keys to sequential hash values. Consequently, efficiency is low.