Data Structure (2130702)

BE | Semester-3   Winter-2017 | 11/14/2017

Q3) (b)

How following hash functions work?

Midsquare Method

  • 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).

Digit Analysis

  • 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.