DBMS Notes
Static hashing suffers when data size changes unpredictably: - Too few buckets → overflow chains → slow - Too many buckets → wasted space
Why Dynamic Hashing?
Static hashing suffers when data size changes unpredictably:
- Too few buckets → overflow chains → slow
- Too many buckets → wasted space
Dynamic hashing allows the hash table to grow and shrink as data changes, maintaining good performance without a fixed bucket count.
Two main forms:
- Extendible Hashing — directory-based, doubles directory on overflow
- Linear Hashing — directory-free, adds one bucket at a time
Search in Extendible Hashing
| Example | Global depth = 2, K=6, h(6) = ...10... |
| First 2 bits = "10" | index 2 → Bucket C |
| Search Bucket C for K=6 | Found! |
| Cost | 1 directory read + 1 bucket read |
Insert with Bucket Split
| Case 1 | Local depth j < Global depth i |
| Case 2 | Local depth j = Global depth i |
| Example | Insert into full Bucket A (local depth 2 = global depth 2) |
| Step 1: Double directory: global depth 2 | 3 (4 entries → 8 entries) |
| Step 2 | Split Bucket A into A and A' |
| Step 3 | Redistribute records using 3-bit prefix |
Extendible Hashing Diagram (After Split)
| BEFORE (Global depth 2) | AFTER INSERT (Global depth 3): |
| Dir | Bucket: Dir (8 entries): Bucket: |
| Insert 15 into B (full) | 101 ─► B' [15] |
Linear Hashing
Concept
Linear hashing adds one bucket at a time in a predetermined linear order, without using a directory. It uses a sequence of hash functions.
Linear Hashing Lookup
When to Split
A split is triggered when the load factor exceeds a threshold (e.g., 0.8):
Extendible vs. Linear Hashing
| Feature | Extendible Hash | Linear Hash |
|---|---|---|
| Directory | Yes (doubles) | No (dir-free) |
| Split trigger | Bucket overflow | Load factor |
| Buckets added | One at a time | One at a time |
| Directory overhead | Can double | None |
| Implementation | Moderate | Slightly complex |
| Search cost | 1 dir + 1 bucket | O(1) — 1 bucket |
Dynamic Hashing vs. Static Hashing
Continue the lesson path