DBMS Topics
Hashing Techniques
Last Updated : 21 May, 2026
Hashing is a technique for direct address computation — a hash function maps a key value directly to a bucket address disk block where the record is stored. It avoids the
What is Hashing?
Hashing is a technique for direct address computation — a hash function maps a key value directly to a bucket address (disk block) where the record is stored. It avoids the need for traversing an index structure.
Hash Function
A hash function h maps search-key values to a set of bucket addresses (integers 0 to B−1):
Example
| B = 5 buckets, Keys | 101, 102, 103, 204, 305 |
| h(101) = 101 mod 5 = 1 | Bucket 1 |
| h(102) = 102 mod 5 = 2 | Bucket 2 |
| h(103) = 103 mod 5 = 3 | Bucket 3 |
| h(204) = 204 mod 5 = 4 | Bucket 4 |
| h(305) = 305 mod 5 = 0 | Bucket 0 |
| Bucket 0 | [E305] |
| Bucket 1 | [E101] |
| Bucket 2 | [E102] |
| Bucket 3 | [E103] |
| Bucket 4 | [E204] |
Collisions
A collision occurs when two different keys hash to the same bucket:
Collision Resolution
1. Open Addressing (within buckets):
- Each bucket has multiple slots
- If a collision occurs, place the record in the same bucket (multiple records per bucket)
- If bucket is full → use overflow chaining (linked list of overflow blocks)
2. Chaining:
- Each bucket is a linked list of records or overflow pages
- Unlimited records per bucket in theory
Types of Hashing
Hashing vs. Indexing (B+ Tree)
| Feature | Hashing | B+ Tree Index |
|---|---|---|
| Equality search | O(1) — excellent | O(log n) |
| Range query | Poor (no order) | Excellent (sorted) |
| Insertion | O(1) avg | O(log n) |
| Storage | May waste space (empty buckets) | Space-efficient |
| Ordering | No | Yes |
| Skew handling | Can be poor | Handles well |
Use hashing when: Only equality searches needed (e.g., WHERE emp_id = 105) Use B+ Tree when: Range queries needed (e.g., WHERE salary BETWEEN 50000 AND 80000)
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Hashing Techniques.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this DBMS topic.
Search Terms
dbms, database management system, database notes, sql, unit, hashing, techniques, hashing techniques
Related DBMS Topics