Tuesday 10 July 2012

Hash Function : Direct Hashing

This is the simplest hash function – h (n) = n

E.g. To find record of roll number 40, h (40) will give address of the record. Address is generated using the key value. This works only when keys are densely packed i.e. every key is associated with a record. This is not a very popular hash function as it leads to dense organization. If key of a record is 5 then the record must also be placed at address 5.

Problems with direct hashing – 
  1. For a business you considered 100 entries of customers hence allocated continuous space to store 100 records. The record for customer id 1 was placed at address 1, for customer id 2 was placed at address 2 and so on. The space with address 101 to 180 is allocated to some other file. Now the business flourishes and there is a need to enter record for customer with customer id 101. According to hash function we have to place the file at address 101 but it is already occupied. Hence the file cannot grow. The solution can be Relative hashing.
  2. This scheme doesn't let you perform disk defragmentation. Hence this is not practically acceptable. 

No comments:

Post a Comment

Your comments are very much valuable for us. Thanks for giving your precious time.

Do you like this article?