Dynamic hashing is an improved hashing technique used in DBMS to handle growing and shrinking data efficiently. Unlike static hashing—where the number of buckets stays fixed—dynamic hashing can increase or decrease the number of buckets as needed. This makes it ideal for large or expanding databases.
In this method, when more records are inserted, new buckets can be created automatically, preventing bucket overflow. Similarly, if records are deleted and space becomes free, buckets can be merged or removed. Because the structure adjusts itself based on the amount of data, searching, inserting, and deleting records becomes faster and more efficient.
In short, dynamic hashing ensures that the database can scale smoothly without performance loss, making it far more flexible than static hashing.Important Terminologies Related to Dynamic Hashing
- Hash Function: A mathematical function that uses the primary key to generate the address of the data block.
- Data Bucket: These are the memory locations that contain actual data records.
- Hash Index: It is the address of the data block generated by hash function.
- Bucket Overflow: Bucket overflow occurs when memory address generated by the hash function is already filled by some data records.
How to Search a Key?
- Calculate the hash address of key.
- Calculate the number of bits used in the dictionary and denote these bits as i.
- Take the least significant i bits of hash address. This provides index of dictionary.
- This index is used to navigate to the dictionary and check for bucket address in which record may be present.
Advantages of Dynamic Hashing
- Scales smoothly with data growth – Performance remains stable even as the database becomes large.
- Efficient memory usage – Only the required number of buckets are maintained, reducing wasted space.
- Easy record insertion and deletion – The structure grows or shrinks automatically based on data changes.
- Reduces overflow issues – Expanding buckets dynamically helps avoid frequent overflow problems seen in static hashing.
- Flexible for dynamic databases – Ideal for applications where data size changes often.
Disadvantages of Dynamic Hashing
- Complex bucket address table – Keeping track of changing bucket addresses becomes difficult as data grows.
- Higher maintenance overhead – Frequent splitting and merging of buckets requires extra processing.
- Bucket overflow still possible – Although reduced, overflow cannot be completely eliminated.
- More complex implementation – Harder to design and manage compared to static hashing.
- Extra memory for directory/table – The directory structure (like in extendible hashing) consumes additional memory.
How to Insert a New Record in Database Using Dynamic Hashing?
- Follow the same procedure that we used for searching which to lead to some bucket.
- If space is present in that bucket, then place record in it.
- If bucket is full, then split the bucket and redistribute the records.
Example
Consider the following table which contain key into bucket based on their hash address prefix
Key | Hash Address |
|---|---|
1 | 10000 |
2 | 10101 |
3 | 11000 |
4 | 10011 |
5 | 11011 |
6 | 11001 |
7 | 10110 |
In the above table, the last two bits of 1 and 3 are 00. So, it will go into bucket B0. The last two bits of 2 and 6 are 01. So, it will go into bucket B1. The last bit of 7 is 10. So, it will go into bucket B2. The last two bits of 4 and 5 are 11. So, they will go into B3.

Now, to insert key 11 with hash address 10001 into the above structure follow the steps:-
- Since, hash address of the bucket is 10001. It will go into bucket B1. But B1 bucket is already filled, so it will get split.
- Three bits of 11 and 6 are 001. So, they will go into bucket B1. And last three bits of 2 are 101. So, it will go into B4.
- Keys 1 and 3 are still in bucket B0. The record B is pointed by 000 and 100 entry because last two bits of both the entry are 00.
- Key 7 is still in bucket B2. The record B2 is pointed by 010 and 110 entry because last two bits of both the entry are 10.
- Key 4 and 5 are still in bucket B3. The record B3 is pointed by 111 and 011 entry because last two bits of both the entry are 11.
